
    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 3D input.    N)Layer)	InputSpec)
conv_utils)keras_exportzkeras.layers.Cropping3Dc                   J   ^  \ 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
$ )	
Cropping3D   a  Cropping layer for 3D data (e.g. spatial or spatio-temporal).

  Examples:

>>> input_shape = (2, 28, 28, 10, 3)
>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
>>> y = tf.keras.layers.Cropping3D(cropping=(2, 4, 2))(x)
>>> print(y.shape)
(2, 24, 20, 6, 3)

Args:
  cropping: Int, or tuple of 3 ints, or tuple of 3 tuples of 2 ints.
    - If int: the same symmetric cropping
      is applied to depth, height, and width.
    - If tuple of 3 ints: interpreted as two different
      symmetric cropping values for depth, height, and width:
      `(symmetric_dim1_crop, symmetric_dim2_crop, symmetric_dim3_crop)`.
    - If tuple of 3 tuples of 2 ints: interpreted as
      `((left_dim1_crop, right_dim1_crop), (left_dim2_crop,
        right_dim2_crop), (left_dim3_crop, right_dim3_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, spatial_dim1, spatial_dim2, spatial_dim3, channels)`
    while `channels_first` corresponds to inputs with shape
    `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.
    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:
  5D tensor with shape:
  - If `data_format` is `"channels_last"`:
    `(batch_size, first_axis_to_crop, second_axis_to_crop,
    third_axis_to_crop, depth)`
  - If `data_format` is `"channels_first"`:
    `(batch_size, depth, first_axis_to_crop, second_axis_to_crop,
      third_axis_to_crop)`

Output shape:
  5D tensor with shape:
  - If `data_format` is `"channels_last"`:
    `(batch_size, first_cropped_axis, second_cropped_axis,
    third_cropped_axis, depth)`
  - If `data_format` is `"channels_first"`:
    `(batch_size, depth, first_cropped_axis, second_cropped_axis,
      third_cropped_axis)`
c                   > [         TU ]  " S0 UD6  [        R                  " U5      U l        [        U[        5      (       a  X4X4X44U l        O[        US5      (       av  [        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[        R                  " US   SSSS	9nXEU4U l        O[        SU S35      e[        SS9U l        g )N__len__   z-`cropping` should have 3 elements. Received: .r      z1st entry of croppingT)
allow_zero   z2nd entry of croppingz3rd entry of croppinga  `cropping` should be either an int, a tuple of 3 ints (symmetric_dim1_crop, symmetric_dim2_crop, symmetric_dim3_crop), or a tuple of 3 tuples of 2 ints ((left_dim1_crop, right_dim1_crop), (left_dim2_crop, right_dim2_crop), (left_dim3_crop, right_dim2_crop)). Received:    )ndim )super__init__r   normalize_data_formatdata_format
isinstanceintcroppinghasattrlen
ValueErrornormalize_tupler   
input_spec)selfr   r   kwargsdim1_croppingdim2_croppingdim3_cropping	__class__s          b/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/reshaping/cropping3d.pyr   Cropping3D.__init__Q   s     	"6"%;;KHh$$$$$DM
 Xy))8}! CH:QO  '66Q 7DM '66Q 7DM '66Q 7DM +=IDM &Ja)
 
 $+    c                 z   [         R                  " U5      R                  5       nU R                  S:X  a  US   b,  US   U R                  S   S   -
  U R                  S   S   -
  nOS nUS   b,  US   U R                  S   S   -
  U R                  S   S   -
  nOS nUS   b,  US   U R                  S   S   -
  U R                  S   S   -
  nOS n[         R                  " US   US   X#U/5      $ U R                  S:X  a  US   b,  US   U R                  S   S   -
  U R                  S   S   -
  nOS nUS   b,  US   U R                  S   S   -
  U R                  S   S   -
  nOS nUS   b,  US   U R                  S   S   -
  U R                  S   S   -
  nOS n[         R                  " US   X#XAS   /5      $ g )Nchannels_firstr   r   r   r      channels_last)tfTensorShapeas_listr   r   )r    input_shapedim1dim2dim3s        r&   compute_output_shapeCropping3D.compute_output_shapey   s   nn[199;//1~)NT]]1%5a%884==;KA;NN  1~)NT]]1%5a%884==;KA;NN  1~)NT]]1%5a%884==;KA;NN  >>QQTB  01~)NT]]1%5a%884==;KA;NN  1~)NT]]1%5a%884==;KA;NN  1~)NT]]1%5a%884==;KA;NN  >>QTq>B ' 1r(   c                 8   U R                   S:X  Ga  U R                  S   S   U R                  S   S   s=:X  a  U R                  S   S   s=:X  a  S:X  aG  O  ODUS S 2S S 2U R                  S   S   S 2U R                  S   S   S 2U R                  S   S   S 24   $ U R                  S   S   U R                  S   S   s=:X  a  S:X  aX  O  OUUS S 2S S 2U R                  S   S   S 2U R                  S   S   S 2U R                  S   S   U R                  S   S   * 24   $ U R                  S   S   U R                  S   S   s=:X  a  S:X  aX  O  OUUS S 2S S 2U R                  S   S   U R                  S   S   * 2U R                  S   S   S 2U R                  S   S   S 24   $ U R                  S   S   U R                  S   S   s=:X  a  S:X  aX  O  OUUS S 2S S 2U R                  S   S   S 2U R                  S   S   U R                  S   S   * 2U R                  S   S   S 24   $ U R                  S   S   S:X  af  US S 2S S 2U R                  S   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   S   S:X  af  US S 2S S 2U R                  S   S   U R                  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  af  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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U R                  S   S   U R                  S   S   * 24   $ U R                  S   S   U R                  S   S   s=:X  a  U R                  S   S   s=:X  a  S:X  aG  O  ODUS S 2U R                  S   S   S 2U R                  S   S   S 2U R                  S   S   S 2S S 24   $ U R                  S   S   U R                  S   S   s=:X  a  S:X  aX  O  OUUS S 2U R                  S   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   U R                  S   S   s=:X  a  S:X  aX  O  OUUS S 2U R                  S   S   U R                  S   S   * 2U R                  S   S   S 2U R                  S   S   S 2S S 24   $ U R                  S   S   U R                  S   S   s=:X  a  S:X  aX  O  OUUS S 2U R                  S   S   S 2U R                  S   S   U R                  S   S   * 2U R                  S   S   S 2S S 24   $ U R                  S   S   S:X  af  US S 2U R                  S   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   $ U R                  S   S   S:X  af  US S 2U R                  S   S   U R                  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  af  US S 2U R                  S   S   U R                  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U R                  S   S   U R                  S   S   * 2S S 24   $ )Nr*   r   r   r   )r   r   )r    inputss     r&   callCropping3D.call   sF	   //a #==#A&==#A& 
 MM!$Q')MM!$Q')MM!$Q')	+  q!!$a(8(;@q@MM!$Q')MM!$Q')MM!$Q'4==+;A+>*>>	@  q!!$a(8(;@q@MM!$Q'4==+;A+>*>>MM!$Q')MM!$Q')	+  q!!$a(8(;@q@MM!$Q')MM!$Q'4==+;A+>*>>MM!$Q')	+  q!!$)MM!$Q')MM!$Q'4==+;A+>*>>MM!$Q'4==+;A+>*>>	@  q!!$)MM!$Q'4==+;A+>*>>MM!$Q')MM!$Q'4==+;A+>*>>	@  q!!$)MM!$Q'4==+;A+>*>>MM!$Q'4==+;A+>*>>MM!$Q')	+  a #t}}Q'7':&::a #t}}Q'7':&::a #t}}Q'7':&::	<  a #==#A&==#A& 
 MM!$Q')MM!$Q')MM!$Q')	  q!!$a(8(;@q@MM!$Q')MM!$Q')MM!$Q'4==+;A+>*>>	  q!!$a(8(;@q@MM!$Q'4==+;A+>*>>MM!$Q')MM!$Q')	  q!!$a(8(;@q@MM!$Q')MM!$Q'4==+;A+>*>>MM!$Q')	  q!!$)MM!$Q')MM!$Q'4==+;A+>*>>MM!$Q'4==+;A+>*>>	  q!!$)MM!$Q'4==+;A+>*>>MM!$Q')MM!$Q'4==+;A+>*>>	  q!!$)MM!$Q'4==+;A+>*>>MM!$Q'4==+;A+>*>>MM!$Q')	  a #t}}Q'7':&::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&   r;   Cropping3D.get_config5  sM    "mmD<L<LMg(*D**,-V\\^0DDEEr(   )r   r   r   ))r   r   rB   rB   N)__name__
__module____qualname____firstlineno____doc__r   r4   r8   r;   __static_attributes____classcell__)r%   s   @r&   r   r      s.    1h >B&,P.`JXF Fr(   r   )rG   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>rQ      sG    ) " ! 0 4 ) : '([F [F )[Fr(   