o
    7?e*                     @   sr   d Z ddlm  mZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ G d	d
 d
eZdS )z7Keras abstract base layer for separable nD convolution.    N)activations)constraints)initializers)regularizers)	InputSpec)Convc                       sd   e Zd ZdZ																			d fdd		Zd
d Zdd Z fddZ  ZS )SeparableConvaq  Abstract base layer for separable nD convolution.

    This layer performs a depthwise convolution that acts separately on
    channels, followed by a pointwise convolution that mixes channels.
    If `use_bias` is True and a bias initializer is provided,
    it adds a bias vector to the output.
    It then optionally applies an activation function to produce the final
    output.

    Args:
      rank: An integer, the rank of the convolution, e.g. "2" for 2D
        convolution.
      filters: Integer, the dimensionality of the output space (i.e. the number
        of filters in the convolution).
      kernel_size: A tuple or list of integers specifying the spatial
        dimensions of the filters. Can be a single integer to specify the same
        value for all spatial dimensions.
      strides: A tuple or list of integers specifying the strides
        of the convolution. Can be a single integer to specify the same value
        for all spatial dimensions.
        Specifying any `stride` value != 1 is incompatible with specifying
        any `dilation_rate` value != 1.
      padding: One of `"valid"` or `"same"` (case-insensitive).
        `"valid"` means no padding. `"same"` results in padding with zeros
        evenly to the left/right or up/down of the input such that output has
        the same height/width dimension as the input.
      data_format: A string, one of `channels_last` (default) or
        `channels_first`.  The ordering of the dimensions in the inputs.
        `channels_last` corresponds to inputs with shape
        `(batch_size, ..., channels)` while `channels_first` corresponds to
        inputs with shape `(batch_size, channels, ...)`.
      dilation_rate: An integer or tuple/list of 2 integers, specifying
        the dilation rate to use for dilated convolution.
        Can be a single integer to specify the same value for
        all spatial dimensions.
        Currently, specifying any `dilation_rate` value != 1 is
        incompatible with specifying any stride value != 1.
      depth_multiplier: The number of depthwise convolution output channels for
        each input channel. The total number of depthwise convolution output
        channels will be equal to `num_filters_in * depth_multiplier`.
      activation: Activation function to use.
        If you don't specify anything, no activation is applied
        (see `keras.activations`).
      use_bias: Boolean, whether the layer uses a bias.
      depthwise_initializer: An initializer for the depthwise convolution kernel
        (see `keras.initializers`). If None, then the default initializer
        ('glorot_uniform') will be used.
      pointwise_initializer: An initializer for the pointwise convolution kernel
        (see `keras.initializers`). If None, then the default initializer
        ('glorot_uniform') will be used.
      bias_initializer: An initializer for the bias vector. If None, the default
        initializer ('zeros') will be used (see `keras.initializers`).
      depthwise_regularizer: Optional regularizer for the depthwise
        convolution kernel.
      pointwise_regularizer: Optional regularizer for the pointwise
        convolution kernel.
      bias_regularizer: Optional regularizer for the bias vector.
      activity_regularizer: Optional regularizer function for the output.
      depthwise_constraint: Optional projection function to be applied to the
        depthwise kernel after being updated by an `Optimizer` (e.g. used for
        norm constraints or value constraints for layer weights). The function
        must take as input the unprojected variable and must return the
        projected variable (which must have the same shape). Constraints are
        not safe to use when doing asynchronous distributed training.
      pointwise_constraint: Optional projection function to be applied to the
        pointwise kernel after being updated by an `Optimizer`.
      bias_constraint: Optional projection function to be applied to the
        bias after being updated by an `Optimizer`.
      trainable: Boolean, if `True` the weights of this layer will be marked as
        trainable (and listed in `layer.trainable_weights`).
       validNTglorot_uniformzerosc                    s   t  jd|||||||t|	|
t|t|t||||d| || _t|| _t|| _t|| _	t|| _
t|| _t|| _d S )N)rankfilterskernel_sizestridespaddingdata_formatdilation_rate
activationuse_biasbias_initializerbias_regularizeractivity_regularizerbias_constraint	trainablename )super__init__r   getr   r   depth_multiplierdepthwise_initializerpointwise_initializerdepthwise_regularizerpointwise_regularizerr   depthwise_constraintpointwise_constraint)selfr   r   r   r   r   r   r   r    r   r   r!   r"   r   r#   r$   r   r   r%   r&   r   r   r   kwargs	__class__r   s/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/keras/src/layers/convolutional/base_separable_conv.pyr   e   s4   zSeparableConv.__init__c              	   C   s  t |}|  }|j| jd u rtd| d| dt|| }t| jd ||id| _	| j
|| jf }d| j | j| | jf }| jd|| j| j| jd| jd	| _| jd
|| j| j| jd| jd	| _| jr|| jd| jf| j| j| jd| jd	| _nd | _d| _d S )NzSThe channel dimension of the inputs should be defined. The input_shape received is z, where axis z> (0-based) is the channel dimension, which found to be `None`.   )ndimZaxes)r	   depthwise_kernelT)r   shapeZinitializerZregularizer
constraintr   dtypepointwise_kernelbias)tfZTensorShapeZ_get_channel_axisdimsvalue
ValueErrorintr   r   Z
input_specr   r    r   Z
add_weightr!   r#   r%   r1   r.   r"   r$   r&   r2   r   r   r   r   r3   Zbuilt)r'   Zinput_shapeZchannel_axisZ	input_dimZdepthwise_kernel_shapeZpointwise_kernel_shaper   r   r+   build   sh   
		


zSeparableConv.buildc                 C   s   t )N)NotImplementedError)r'   Zinputsr   r   r+   call   s   zSeparableConv.callc                    s  i d| j d| jd| jd| jd| jd| jd| jdt| j	d	| j
d
t| jdt| jdt| jdt| jdt| jdt| jdt| jdt| jt| jt| jd}t  }tt| t|  S )Nr   r   r   r   r   r    r   r   r   r!   r"   r   r#   r$   r   r   r%   )r&   r   )r   r   r   r   r   r    r   r   	serializer   r   r   r!   r"   r   r   r#   r$   r   r   r   r%   r&   r   r   
get_configdictlistitems)r'   configZbase_configr)   r   r+   r=      sl   	


#zSeparableConv.get_config)r	   r
   Nr	   r	   NTr   r   r   NNNNNNNTN)	__name__
__module____qualname____doc__r   r9   r;   r=   __classcell__r   r   r)   r+   r      s2    M47r   )rE   Ztensorflow.compat.v2compatv2r4   Z	keras.srcr   r   r   r   Zkeras.src.engine.input_specr   Z(keras.src.layers.convolutional.base_convr   r   r   r   r   r+   <module>   s   