
    &Vfq                     t    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)TFDataLayer)image_utilszkeras.layers.CenterCropc                   :     e Zd ZdZd fd	Zd Zd Z fdZ xZS )
CenterCropa  A preprocessing layer which crops images.

    This layers crops the central portion of the images to a target size. If an
    image is smaller than the target size, it will be resized and cropped
    so as to return the largest possible window in the image that matches
    the target aspect ratio.

    Input pixel values can be of any range (e.g. `[0., 1.)` or `[0, 255]`).

    Input shape:
        3D (unbatched) or 4D (batched) tensor with shape:
        `(..., height, width, channels)`, in `"channels_last"` format,
        or `(..., channels, height, width)`, in `"channels_first"` format.

    Output shape:
        3D (unbatched) or 4D (batched) tensor with shape:
        `(..., target_height, target_width, channels)`,
        or `(..., channels, target_height, target_width)`,
        in `"channels_first"` format.

    If the input height/width is even and the target height/width is odd (or
    inversely), the input image is left-padded by 1 pixel.

    **Note:** This layer is safe to use inside a `tf.data` pipeline
    (independently of which backend you're using).

    Args:
        height: Integer, the height of the output shape.
        width: Integer, the width of the output shape.
        data_format: string, either `"channels_last"` or `"channels_first"`.
            The ordering of the dimensions in the inputs. `"channels_last"`
            corresponds to inputs with shape `(batch, height, width, channels)`
            while `"channels_first"` corresponds to inputs with shape
            `(batch, channels, height, width)`. It defaults to the
            `image_data_format` value found in your Keras config file at
            `~/.keras/keras.json`. If you never set it, then it will be
            `"channels_last"`.
    Nc                      t                      j        di | || _        || _        t	          j        |          | _        d S )N )super__init__heightwidthr   standardize_data_formatdata_format)selfr   r   r   kwargs	__class__s        g/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/layers/preprocessing/center_crop.pyr   zCenterCrop.__init__0   sG    ""6"""
":;GG    c                 |   | j                             || j                  }| j        dk    r|j        d         }|j        d         }n|j        d         }|j        d         }||t          d|j                   || j        z
  }|| j        z
  }t          |dz            }t          |dz            }|dk    r|dk    rt          |j                  dk    rS| j        dk    r$|d d d d ||| j        z   ||| j        z   f         S |d d ||| j        z   ||| j        z   d d f         S t          |j                  d	k    rM| j        dk    r!|d d ||| j        z   ||| j        z   f         S |||| j        z   ||| j        z   d d f         S t          j        || j        | j        g| j        | j         
          S )Nchannels_firstzeAt this time, CenterCrop can only process images with a static spatial shape. Received: inputs.shape=   r         )r   backend_module)r   castcompute_dtyper   shape
ValueErrorr   r   intlenr   smart_resize)r   inputsinit_height
init_widthh_diffw_diffh_startw_starts           r   callzCenterCrop.call6   sH   ""64+=>>/// ,r*Kb)JJ ,r*Kb)J*"4@17@ @   t{*dj(fqj//fqj//Q;;6Q;;6<  A%%#'777!'DK"77'DJ"668  AAg33g
22AA  V\""a''#'777!'DK"77'DJ"668 
 g33g
22AA  '[$*%(<	
 
 
 	
r   c                    t          |          }t          |d         t           t          f          st          |          dvrt	          d          t          |          dk    r5| j        dk    r| j        |d<   | j        |d<   nI| j        |d<   | j        |d<   n4| j        dk    r| j        |d<   | j        |d<   n| j        |d<   | j        |d<   t          |          S )	Nr   )r   r   zc`input_shape` must be a non-nested tuple or list of rank-1 with size 3 (unbatched) or 4 (batched). r   channels_last   r   r   )list
isinstancetupler$   r"   r   r   r   )r   input_shapes     r   compute_output_shapezCenterCrop.compute_output_shapep   s    ;''k!ntUm44 	9
 9
9 9 E   {q  ?22!%A!%A!%A!%A?22!%A!%A!%A!%A[!!!r   c                 z    t                                                      }| j        | j        | j        d}i ||S )N)r   r   r   )r   
get_configr   r   r   )r   base_configconfigr   s      r   r7   zCenterCrop.get_config   sF    gg((**kZ+
 

 )+(((r   )N)	__name__
__module____qualname____doc__r   r-   r5   r7   __classcell__)r   s   @r   r   r      s        % %NH H H H H H8
 8
 8
t" " "2) ) ) ) ) ) ) ) )r   r   N)		keras.srcr   keras.src.api_exportr   ,keras.src.layers.preprocessing.tf_data_layerr   keras.src.utilsr   r   r
   r   r   <module>rC      s          - - - - - - D D D D D D ' ' ' ' ' ' '((H) H) H) H) H) H) H) )(H) H) H)r   