
    &VfD*                     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)SeedGeneratorzkeras.layers.RandomZoomc                   l     e Zd ZdZdZdZdZ	 	 	 	 	 	 d fd		Zd
 Zd Z	ddZ
d Zd Zd Z fdZ xZS )
RandomZooma  A preprocessing layer which randomly zooms images during training.

    This layer will randomly zoom in or out on each axis of an image
    independently, filling empty space according to `fill_mode`.

    Input pixel values can be of any range (e.g. `[0., 1.)` or `[0, 255]`) and
    of integer or floating point dtype.
    By default, the layer will output floats.

    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.

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

    Args:
        height_factor: a float represented as fraction of value, or a tuple of
            size 2 representing lower and upper bound for zooming vertically.
            When represented as a single float, this value is used for both the
            upper and lower bound. A positive value means zooming out, while a
            negative value means zooming in. For instance,
            `height_factor=(0.2, 0.3)` result in an output zoomed out by a
            random amount in the range `[+20%, +30%]`.
            `height_factor=(-0.3, -0.2)` result in an output zoomed in by a
            random amount in the range `[+20%, +30%]`.
        width_factor: a float represented as fraction of value, or a tuple of
            size 2 representing lower and upper bound for zooming horizontally.
            When represented as a single float, this value is used for both the
            upper and lower bound. For instance, `width_factor=(0.2, 0.3)`
            result in an output zooming out between 20% to 30%.
            `width_factor=(-0.3, -0.2)` result in an output zooming in between
            20% to 30%. `None` means i.e., zooming vertical and horizontal
            directions by preserving the aspect ratio. Defaults to `None`.
        fill_mode: Points outside the boundaries of the input are filled
            according to the given mode. Available methods are `"constant"`,
            `"nearest"`, `"wrap"` and `"reflect"`. Defaults to `"constant"`.
            - `"reflect"`: `(d c b a | a b c d | d c b a)`
                The input is extended by reflecting about the edge of the last
                pixel.
            - `"constant"`: `(k k k k | a b c d | k k k k)`
                The input is extended by filling all values beyond
                the edge with the same constant value k specified by
                `fill_value`.
            - `"wrap"`: `(a b c d | a b c d | a b c d)`
                The input is extended by wrapping around to the opposite edge.
            - `"nearest"`: `(a a a a | a b c d | d d d d)`
                The input is extended by the nearest pixel.
            Note that when using torch backend, `"reflect"` is redirected to
            `"mirror"` `(c d c b | a b c d | c b a b)` because torch does not
            support `"reflect"`.
            Note that torch backend does not support `"wrap"`.
        interpolation: Interpolation mode. Supported values: `"nearest"`,
            `"bilinear"`.
        seed: Integer. Used to create a random seed.
        fill_value: a float that represents the value to be filled outside
            the boundaries when `fill_mode="constant"`.
        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"`.
        **kwargs: Base layer keyword arguments, such as `name` and `dtype`.

    Example:

    >>> input_img = np.random.random((32, 224, 224, 3))
    >>> layer = keras.layers.RandomZoom(.5, .2)
    >>> out_img = layer(input_img)
    z^The `factor` argument should be a number (or a list of two numbers) in the range [-1.0, 1.0]. )reflectwrapconstantnearest)r   bilinearNr	   r           c                     t                      j        di | || _        |                     |d          \  | _        | _        || _        |#|                     |d          \  | _        | _        || j	        vrt          d| d| j	         d          || j        vrt          d| d| j         d          || _        || _        || _        || _        t!          |          | _        t%          j        |          | _        d| _        d S )	Nheight_factorwidth_factorzUnknown `fill_mode` z. Expected of one .zUnknown `interpolation` F )super__init__r   _set_factorheight_lowerheight_upperr   width_lowerwidth_upper_SUPPORTED_FILL_MODENotImplementedError_SUPPORTED_INTERPOLATION	fill_mode
fill_valueinterpolationseedr   	generatorr   standardize_data_formatdata_formatsupports_jit)
selfr   r   r   r    r!   r   r$   kwargs	__class__s
            g/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/layers/preprocessing/random_zoom.pyr   zRandomZoom.__init__a   sc    	""6"""*/3/?/??0
 0
,4, )#151A1An2 2.Dd. D555%0y 0 0,0 0 0    ===%4= 4 404 4 4  
 #$*	&t,,":;GG!    c                     t          |t          t          f          ryt          |          dk    rt	          | j        d| d| z             |                     |d                    |                     |d                    t          |          \  }}nft          |t          t          f          r-|                     |           t          |          }| |g\  }}nt	          | j        d| d| z             ||fS )N   z
Received: =r      )
isinstancetuplelistlen
ValueError_FACTOR_VALIDATION_ERROR_check_factor_rangesortedintfloatabs)r&   factorfactor_nameloweruppers        r)   r   zRandomZoom._set_factor   s   fudm,, 	6{{a 19;9999:   $$VAY///$$VAY///!&>>LE55e-- 	$$V,,,[[F#GV,LE55-5{55V556   e|r*   c                 R    |dk    s|dk     rt          | j        d| z             d S )N      ?g      zReceived: input_number=)r3   r4   )r&   input_numbers     r)   r5   zRandomZoom._check_factor_range   sG    #!4!4-:L::;   "5!4r*   Tc                 t    | j                             || j                  }|r|                     |          S |S N)r   castcompute_dtype_randomly_zoom_inputs)r&   inputstrainings      r)   callzRandomZoom.call   s=    ""64+=>> 	--f555Mr*   c                    | j                             |          }t          |          dk    }|r;| j         j                            |d          }| j                             |          }|d         }| j        dk    r|d         }|d         }n|d         }|d         }|                     | j         j                  }| j         j        	                    d| j
        z   d| j        z   |d	g|
          }| j        6| j         j        	                    d| j        z   d| j        z   |d	g|
          }	n|}	| j                             | j         j                            |	|gd	          d          }
| j         j                            ||                     |
||          | j        | j        | j        | j                  }|r!| j         j                            |d          }|S )N   r   axischannels_firstr?   r.   )minvalmaxvalshaper!   float32)dtype)	transformr    r   r   r$   )r   rS   r2   numpyexpand_dimsr$   _get_seed_generator_backendrandomuniformr   r   r   r   r   rC   concatenateimageaffine_transform_get_zoom_matrixr    r   r   squeeze)r&   rF   inputs_shape	unbatched
batch_sizeheightwidthseed_generatorheight_zoom
width_zoomzoomsoutputss               r)   rE   z RandomZoom._randomly_zoom_inputs   s
   |))&11%%*	 	6\'33F3CCF<--f55L!!_
///!"%F $EE!"%F $E11$,2GHHl)11****q/	 2 
 
 (,44T--T--!1o#	 5  JJ %J!!L**J+D1*MM " 
 

 ,$55++E65AA,n( 6 
 
  	Bl(00q0AAGr*   c                 H   | j                             |          d         }| j                             |d          dz
  dz  d|d d ddf         z
  z  }| j                             |d          dz
  dz  d|d d dd f         z
  z  }| j         j                            |d d ddf         | j         j                            |df          || j         j                            |df          |d d dd f         || j         j                            |df          gd          S )Nr   rT   r?   g       @r.   r,   rK   )r   rS   rC   rW   r]   zeros)r&   rj   image_heightimage_width	num_zoomsx_offsety_offsets          r)   r`   zRandomZoom._get_zoom_matrix   sD   L&&u--a0	 \&&{I>>DK%1Q3-
 \|Y77#=D5ABB<! |!--aaa1f"(()Q88"(()Q88aaae"(()Q88  . 
 
 	
r*   c                     |S rB   r   )r&   input_shapes     r)   compute_output_shapezRandomZoom.compute_output_shape   s    r*   c                     t                                                      }| j        | j        | j        | j        | j        | j        | j        d}i ||S )N)r   r   r   r    r!   r   r$   )	r   
get_configr   r   r   r    r!   r   r$   )r&   base_configconfigr(   s      r)   rw   zRandomZoom.get_config   s]    gg((**!/ -!/I/+
 
 )+(((r*   )Nr	   r   Nr   N)T)__name__
__module____qualname____doc__r4   r   r   r   r   r5   rH   rE   r`   ru   rw   __classcell__)r(   s   @r)   r   r      s        O Od	%  F6
  '" '" '" '" '" '"R  *     / / /b
 
 
6  ) ) ) ) ) ) ) ) )r*   r   N)		keras.srcr   keras.src.api_exportr   ,keras.src.layers.preprocessing.tf_data_layerr   keras.src.random.seed_generatorr   r   r   r*   r)   <module>r      s          - - - - - - D D D D D D 9 9 9 9 9 9 '(() ) ) ) ) ) ) )() ) )r*   