a
    Sic²   ã                   @   sb   d Z ddlm  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	„ d	eƒƒZdS )
z"Keras cropping layer for 2D input.é    N)ÚLayer)Ú	InputSpec)Ú
conv_utils)Úkeras_exportzkeras.layers.Cropping2Dc                       s>   e Zd ZdZd‡ fdd„	Zdd„ Zdd	„ Z‡ fd
d„Z‡  ZS )Ú
Cropping2DaK  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)`.
        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".

    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)`
    ©©r   r   r   Nc                    sº   t ƒ jf i |¤Ž t |¡| _t|tƒr<||f||ff| _nnt|dƒršt	|ƒdkrbt
d|› dƒ‚tj|d dddd}tj|d	 dd
dd}||f| _nt
d|› dƒ‚tdd| _d S )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__© ú]/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/layers/reshaping/cropping2d.pyr   O   s0    

ÿÿÿÿûÿzCropping2D.__init__c                 C   s   t  |¡ ¡ }| jdkrŠt  |d |d |d rT|d | jd d  | jd d  nd |d r‚|d | jd d  | jd d  nd g¡S t  |d |d rÀ|d | jd d  | jd d  nd |d rî|d | jd d  | jd d  nd |d g¡S d S )NÚchannels_firstr   r   r
   é   )ÚtfÚTensorShapeÚas_listr   r   )r   Úinput_shaper"   r"   r#   Úcompute_output_shapel   s0    
ÿ&ÿ&øÿÿ&ÿ&øÿzCropping2D.compute_output_shapec                 C   sŒ  | j dkrÄ|jd d ur2t| jd ƒ|jd ksX|jd d urpt| jd ƒ|jd krptd|j› d| j› ƒ‚| jd d | jd d   kr˜dkrÐn n4|d d …d d …| jd d d …| jd d d …f S | jd d dkr$|d d …d d …| jd d d …| jd d | jd d  …f S | jd d dkrx|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 d urît| jd ƒ|jd ks|jd d ur0t| jd ƒ|jd kr0td|j› d| j› ƒ‚| jd d | jd d   kr\dkr”n n4|d d …| jd d d …| jd d d …d d …f S | jd d dkrè|d d …| jd d d …| jd d | jd d  …d d …f S | jd d dkr<|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 d S )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   Úinputsr"   r"   r#   ÚcallŠ   sª    ÿþüûþþÿ,.ÿýÿýÿýÿÿþüûþþÿ0.ÿýÿýÿýÿzCropping2D.callc                    s4   | j | jdœ}tƒ  ¡ }tt| ¡ ƒt| ¡ ƒ ƒS )N)r   r   )r   r   r   Ú
get_configÚdictÚlistÚitems)r   ÚconfigÚbase_configr    r"   r#   r/   ×   s    
zCropping2D.get_config)r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   r.   r/   Ú__classcell__r"   r"   r    r#   r      s
   1Mr   )r8   Útensorflow.compat.v2ÚcompatÚv2r&   Úkeras.engine.base_layerr   Úkeras.engine.input_specr   Úkeras.utilsr   Ú tensorflow.python.util.tf_exportr   r   r"   r"   r"   r#   Ú<module>   s   