
    &Vf&                         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
  ed           G d d	e                      Zd
S )    )backend)ops)keras_export)	InputSpec)Layer)argument_validationzkeras.layers.ZeroPadding2Dc                   :     e Zd ZdZd fd	Zd Zd Z fdZ xZS )	ZeroPadding2DaA  Zero-padding layer for 2D input (e.g. picture).

    This layer can add rows and columns of zeros at the top, bottom, left and
    right side of an image tensor.

    Example:

    >>> input_shape = (1, 1, 2, 2)
    >>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
    >>> x
    [[[[0 1]
       [2 3]]]]
    >>> y = keras.layers.ZeroPadding2D(padding=1)(x)
    >>> y
    [[[[0 0]
       [0 0]
       [0 0]
       [0 0]]
      [[0 0]
       [0 1]
       [2 3]
       [0 0]]
      [[0 0]
       [0 0]
       [0 0]
       [0 0]]]]

    Args:
        padding: Int, or tuple of 2 ints, or tuple of 2 tuples of 2 ints.
            - If int: the same symmetric padding is applied to height and width.
            - If tuple of 2 ints: interpreted as two different symmetric padding
              values for height and width:
              `(symmetric_height_pad, symmetric_width_pad)`.
            - If tuple of 2 tuples of 2 ints: interpreted as
             `((top_pad, bottom_pad), (left_pad, right_pad))`.
        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, height, width, channels)` while `"channels_first"`
            corresponds to inputs with shape
            `(batch_size, channels, height, width)`.
            When unspecified, uses `image_data_format` value found in your Keras
            config file at `~/.keras/keras.json` (if exists). Defaults to
            `"channels_last"`.

    Input shape:
        4D tensor with shape:
        - If `data_format` is `"channels_last"`:
          `(batch_size, height, width, channels)`
        - If `data_format` is `"channels_first"`:
          `(batch_size, channels, height, width)`

    Output shape:
        4D tensor with shape:
        - If `data_format` is `"channels_last"`:
          `(batch_size, padded_height, padded_width, channels)`
        - If `data_format` is `"channels_first"`:
          `(batch_size, channels, padded_height, padded_width)`
       r   Nc                     t                      j        di | t          j        |          | _        t          |t                    r||f||ff| _        nt          |d          rlt          |          dk    rt          d| d          t          j        |d         ddd          }t          j        |d	         dd
d          }||f| _        nt          d| d          t          d          | _        d S )N__len__   z6`padding` should have two elements. Received: padding=.r   z1st entry of paddingT)
allow_zeror   z2nd entry of paddingz`padding` should be either an int, a tuple of 2 ints (symmetric_height_crop, symmetric_width_crop), or a tuple of 2 tuples of 2 ints ((top_crop, bottom_crop), (left_crop, right_crop)). Received: padding=   )ndim )super__init__r   standardize_data_formatdata_format
isinstanceintpaddinghasattrlen
ValueErrorr   standardize_tupler   
input_spec)selfr   r   kwargsheight_paddingwidth_padding	__class__s         f/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/layers/reshaping/zero_padding2d.pyr   zZeroPadding2D.__init__G   sJ   ""6"""":;GGgs## 	$g.'0BCDLLWi(( 	7||q   4)04 4 4   1B
A5$  N 0A
A5$  M +M:DLL0 &-	0 0 0   $+++    c                    t          |          }| j        dk    rdnd}t          dd          D ]E}|||z            8|||z   xx         | j        |         d         | j        |         d         z   z  cc<   Ft	          |          S )Nchannels_firstr   r   r   )listr   ranger   tuple)r!   input_shapeoutput_shapespatial_dims_offsetindexs        r&   compute_output_shapez"ZeroPadding2D.compute_output_shapec   s    K((#'#37G#G#GaaQ1a[[ 	 	EE$778DU%88999L'*T\%-@-CC999 \"""r'   c                 v    | j         dk    rddg| j        R }ndg| j        dR }t          j        ||          S )Nr)   )r   r   )r   r   r   pad)r!   inputsall_dims_paddings      r&   callzZeroPadding2D.callm   sT    /// &>>> &>>v>>wv/000r'   c                 n    | j         | j        d}t                                                      }i ||S )N)r   r   )r   r   r   
get_config)r!   configbase_configr%   s      r&   r8   zZeroPadding2D.get_configt   s:    !\$:JKKgg((**(+(((r'   )r   N)	__name__
__module____qualname____doc__r   r1   r6   r8   __classcell__)r%   s   @r&   r
   r
   	   s        : :x, , , , , ,8# # #1 1 1) ) ) ) ) ) ) ) )r'   r
   N)	keras.srcr   r   keras.src.api_exportr   keras.src.layers.input_specr   keras.src.layers.layerr   keras.src.utilsr   r
   r   r'   r&   <module>rE      s                - - - - - - 1 1 1 1 1 1 ( ( ( ( ( ( / / / / / / *++m) m) m) m) m)E m) m) ,+m) m) m)r'   