
    &VfT#                         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)keras_export)	InputSpec)Layer)argument_validationzkeras.layers.Cropping2Dc                   :     e Zd ZdZd fd	Zd Zd Z fdZ xZS )	
Cropping2Da  Cropping layer for 2D input (e.g. picture).

    It crops along spatial dimensions, i.e. height and width.

    Example:

    >>> input_shape = (2, 28, 28, 3)
    >>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
    >>> y = keras.layers.Cropping2D(cropping=((2, 2), (4, 4)))(x)
    >>> y.shape
    (2, 24, 20, 3)

    Args:
        cropping: Int, or tuple of 2 ints, or tuple of 2 tuples of 2 ints.
            - If int: the same symmetric cropping is applied to height and
              width.
            - If tuple of 2 ints: interpreted as two different symmetric
              cropping values for height and width:
              `(symmetric_height_crop, symmetric_width_crop)`.
            - If tuple of 2 tuples of 2 ints: interpreted as
              `((top_crop, bottom_crop), (left_crop, right_crop))`.
        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, cropped_height, cropped_width, channels)`
        - If `data_format` is `"channels_first"`:
          `(batch_size, channels, cropped_height, cropped_width)`
    r   r   r   Nc                 ,    t                      j        di | t          j        |          | _        t          |t                    r'|dk     rt          d| d          ||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 )Nr   z2`cropping` cannot be negative. Received: cropping=.__len__   z8`cropping` should have two elements. Received: cropping=z1st entry of croppingT)
allow_zero   z2nd entry of croppingz`cropping` 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: cropping=   )ndim )super__init__r   standardize_data_formatdata_format
isinstanceint
ValueErrorcroppinghasattrlenr   standardize_tupler   
input_spec)selfr   r   kwargsheight_croppingwidth_cropping	__class__s         b/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/layers/reshaping/cropping2d.pyr   zCropping2D.__init__8   s~   ""6"""":;GGh$$ 	!|| 6*26 6 6   '1Hh3GHDMMXy)) 	8}}!! 6*26 6 6   2CQ 7D  O 1BQ 7D  N -n=DMM2 '/	2 2 2   $+++    c                    | j         dk    r|d         $t          | j        d                   |d         k    s,|d         >t          | j        d                   |d         k    rt          d| d| j                   |d         |d         |d         0|d         | j        d         d         z
  | j        d         d         z
  nd |d         0|d         | j        d         d         z
  | j        d         d         z
  nd fS |d         $t          | j        d                   |d         k    s,|d         >t          | j        d                   |d         k    rt          d| d| j                   |d         |d         0|d         | j        d         d         z
  | j        d         d         z
  nd |d         0|d         | j        d         d         z
  | j        d         d         z
  nd |d         fS )Nchannels_firstr   r      r   z}Values in `cropping` argument should be smaller than the corresponding spatial dimension of the input. Received: input_shape=, cropping=)r   sumr   r   )r!   input_shapes     r&   compute_output_shapezCropping2D.compute_output_shapeY   sK   ///A*a())[^;;A*a())[^;; K#.K K;?=K K   AA #1~1  NT]1%5a%884=;KA;NNN #1~1  NT]1%5a%884=;KA;NNN   A*a())[^;;A*a())[^;; K#.K K;?=K K   A #1~1  NT]1%5a%884=;KA;NNN #1~1  NT]1%5a%884=;KA;NNNA r'   c                 F   | j         dk    r|j        d         )t          | j        d                   |j        d         k    s6|j        d         Ht          | j        d                   |j        d         k    rt	          d|j         d| j                   | j        d         d         | j        d         d         cxk    rdk    r9n n6|d d d d | j        d         d         d | j        d         d         d f         S | j        d         d         dk    rH|d d d d | j        d         d         d | j        d         d         | j        d         d          f         S | j        d         d         dk    rH|d d d d | j        d         d         | j        d         d          | j        d         d         d f         S |d d d d | j        d         d         | j        d         d          | j        d         d         | j        d         d          f         S |j        d         )t          | j        d                   |j        d         k    s6|j        d         Ht          | j        d                   |j        d         k    rt	          d|j         d| j                   | j        d         d         | j        d         d         cxk    rdk    r9n n6|d d | j        d         d         d | j        d         d         d d d f         S | j        d         d         dk    rH|d d | j        d         d         d | j        d         d         | j        d         d          d d f         S | j        d         d         dk    rH|d d | j        d         d         | j        d         d          | j        d         d         d d d f         S |d d | j        d         d         | j        d         d          | j        d         d         | j        d         d          d d f         S )Nr)   r   r   r*   r   z~Values in `cropping` argument should be smaller than the corresponding spatial dimension of the input. Received: inputs.shape=r+   )r   shaper,   r   r   )r!   inputss     r&   callzCropping2D.call   s   ///Q+a())V\!_<<Q+a())V\!_<< M$*LM M=A]M M  
 }Q"dmA&6q&9>>>>Q>>>>>AAqqq$-*1-//q1A!1D1F1FF  q!!$))AAAAM!$Q'))M!$Q'4=+;A+>*>>@  q!!$))AAAAM!$Q'4=+;A+>*>>M!$Q'))+  a #t}Q'7':&::a #t}Q'7':&::<  Q+a())V\!_<<Q+a())V\!_<< M$*LM M=A]M M  
 }Q"dmA&6q&9>>>>Q>>>>>AAt}Q'*,,dmA.>q.A.C.CQQQF  q!!$))AAM!$Q'))M!$Q'4=+;A+>*>>AA  q!!$))AAM!$Q'4=+;A+>*>>M!$Q'))AA  a #t}Q'7':&::a #t}Q'7':&:: r'   c                 n    | j         | j        d}t                                                      }i ||S )N)r   r   )r   r   r   
get_config)r!   configbase_configr%   s      r&   r4   zCropping2D.get_config   s:    "mD<LMMgg((**(+(((r'   )r
   N)	__name__
__module____qualname____doc__r   r.   r2   r4   __classcell__)r%   s   @r&   r	   r	      s        , ,\, , , , , ,B6 6 6pJ J JX) ) ) ) ) ) ) ) )r'   r	   N)	keras.srcr   keras.src.api_exportr   keras.src.layers.input_specr   keras.src.layers.layerr   keras.src.utilsr   r	   r   r'   r&   <module>rA      s          - - - - - - 1 1 1 1 1 1 ( ( ( ( ( ( / / / / / / '((W) W) W) W) W) W) W) )(W) W) W)r'   