
    6bi                      v    S r SSKJs  Jr  SSKJr  SSKJr  SSK	J
r
  SSKJr  \" S5       " S S	\5      5       rg)
z"Keras cropping layer for 2D input.    N)Layer)	InputSpec)
conv_utils)keras_exportzkeras.layers.Cropping2Dc                   H   ^  \ rS rSrSrSU 4S jjrS rS rU 4S jrSr	U =r
$ )	
Cropping2D   a  Cropping layer for 2D input (e.g. picture).

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

Examples:

>>> input_shape = (2, 28, 28, 3)
>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
>>> y = tf.keras.layers.Cropping2D(cropping=((2, 2), (4, 4)))(x)
>>> print(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 TF-Keras config file at
     `~/.keras/keras.json` (if exists) else 'channels_last'.
    Defaults to 'channels_last'.

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

Output shape:
  4D tensor with shape:
  - If `data_format` is `"channels_last"`:
    `(batch_size, cropped_rows, cropped_cols, channels)`
  - If `data_format` is `"channels_first"`:
    `(batch_size, channels, cropped_rows, cropped_cols)`
c                   > [         TU ]  " S0 UD6  [        R                  " U5      U l        [        U[        5      (       a  X4X44U l        O{[        US5      (       a[  [        U5      S:w  a  [        SU S35      e[        R                  " US   SSSS9n[        R                  " US	   SS
SS9nXE4U l        O[        SU S35      e[        SS9U l        g )N__len__   z/`cropping` should have two elements. Received: .r   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:    )ndim )super__init__r   normalize_data_formatdata_format
isinstanceintcroppinghasattrlen
ValueErrornormalize_tupler   
input_spec)selfr   r   kwargsheight_croppingwidth_cropping	__class__s         b/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/reshaping/cropping2d.pyr   Cropping2D.__init__P   s    "6"%;;KHh$$&1H3GHDMXy))8}! !!)
!-  )88Q 7DO (77Q 7DN -=DM
 &Ja)  $+    c                    [         R                  " U5      R                  5       nU R                  S:X  a  [         R                  " US   US   US   (       a+  US   U R                  S   S   -
  U R                  S   S   -
  OS US   (       a0  US   U R                  S   S   -
  U R                  S   S   -
  /5      $ S /5      $ [         R                  " US   US   (       a+  US   U R                  S   S   -
  U R                  S   S   -
  OS US   (       a+  US   U R                  S   S   -
  U R                  S   S   -
  OS US   /5      $ )Nchannels_firstr   r   r      )tfTensorShapeas_listr   r   )r   input_shapes     r$   compute_output_shapeCropping2D.compute_output_shapem   sg   nn[199;//>>NN"1~  NT]]1%5a%884==;KA;NN"1~  NT]]1%5a%884==;KA;NN	  	  >>N"1~  NT]]1%5a%884==;KA;NN"1~  NT]]1%5a%884==;KA;NNN	 r&   c                    U R                   S:X  Ga  UR                  S   b)  [        U R                  S   5      UR                  S   :  d9  UR                  S   bN  [        U R                  S   5      UR                  S   :  a%  [	        SUR                   SU R                   35      eU R                  S   S   U R                  S   S   s=:X  a  S:X  a4  O  O1US S 2S S 2U R                  S   S   S 2U R                  S   S   S 24   $ U R                  S   S   S:X  aB  US S 2S S 2U R                  S   S   S 2U R                  S   S   U R                  S   S   * 24   $ U R                  S   S   S:X  aB  US S 2S S 2U R                  S   S   U R                  S   S   * 2U R                  S   S   S 24   $ US S 2S S 2U R                  S   S   U R                  S   S   * 2U R                  S   S   U R                  S   S   * 24   $ UR                  S   b)  [        U R                  S   5      UR                  S   :  d9  UR                  S   bN  [        U R                  S   5      UR                  S   :  a%  [	        SUR                   SU R                   35      eU R                  S   S   U R                  S   S   s=:X  a  S:X  a4  O  O1US S 2U R                  S   S   S 2U R                  S   S   S 2S S 24   $ U R                  S   S   S:X  aB  US S 2U R                  S   S   S 2U R                  S   S   U R                  S   S   * 2S S 24   $ U R                  S   S   S:X  aB  US S 2U R                  S   S   U R                  S   S   * 2U R                  S   S   S 2S S 24   $ US S 2U R                  S   S   U R                  S   S   * 2U R                  S   S   U R                  S   S   * 2S S 24   $ )Nr(   r   r   r)   r   zQArgument `cropping` must be greater than the input shape. Received: inputs.shape=z, and cropping=)r   shapesumr   r   )r   inputss     r$   callCropping2D.call   sd   //Q+a()V\\!_<Q+a()V\\!_< L||nODMM?D 
 }}Q"dmmA&6q&9>Q>q$--*1-/q1A!1D1FF  q!!$)MM!$Q')MM!$Q'4==+;A+>*>>@  q!!$)MM!$Q'4==+;A+>*>>MM!$Q')+  a #t}}Q'7':&::a #t}}Q'7':&::<  Q+a()V\\!_<Q+a()V\\!_< L||nODMM?D 
 }}Q"dmmA&6q&9>Q>t}}Q'*,dmmA.>q.A.CQF  q!!$)MM!$Q')MM!$Q'4==+;A+>*>>  q!!$)MM!$Q'4==+;A+>*>>MM!$Q')  a #t}}Q'7':&::a #t}}Q'7':&:: r&   c                    > U R                   U R                  S.n[        TU ]  5       n[	        [        UR                  5       5      [        UR                  5       5      -   5      $ )N)r   r   )r   r   r   
get_configdictlistitems)r   configbase_configr#   s      r$   r7   Cropping2D.get_config   sM    "mmD<L<LMg(*D**,-V\\^0DDEEr&   )r   r   r   ))r   r   r>   N)__name__
__module____qualname____firstlineno____doc__r   r.   r4   r7   __static_attributes____classcell__)r#   s   @r$   r   r      s&    0d,:<JXF Fr&   r   )rC   tensorflow.compat.v2compatv2r*   tf_keras.src.engine.base_layerr   tf_keras.src.engine.input_specr   tf_keras.src.utilsr    tensorflow.python.util.tf_exportr   r   r   r&   r$   <module>rM      sG    ) " ! 0 4 ) : '(}F }F )}Fr&   