
    6bi                       S r SSK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SKJr  SSKJr  S	rS
rS r\" SS5       " S S\R,                  5      5       r\" SS5       " S S\R,                  5      5       r\" SS/ S9 " S S\R2                  5      5       r\" SS5       " S S\R,                  5      5       rSrSrSr\" S S!/ S9 " S" S#\R2                  5      5       r\" S$S%/ S9 " S& S'\R2                  5      5       r SDS( jr!     SES) jr"SDS* jr#\" S+S,/ S9 " S- S.\R2                  5      5       r$\" S/S0/ S9 " S1 S2\R2                  5      5       r%SDS3 jr&\" S4S5/ S9 " S6 S7\R2                  5      5       r'\" S8/ S9 " S9 S:\R2                  5      5       r(\" S;S</ S9 " S= S>\R2                  5      5       r)\" S?S@/ S9 " SA SB\R2                  5      5       r*SDSC jr+g)Fz!Keras image preprocessing layers.    N)keras_export)backend)
base_layer)preprocessing_utils)image_utils)tf_utilsc                 X    U S;  a  [        SU  S35      eUS;  a  [        SU S35      eg )N>   wrapnearestreflectconstantzUnknown `fill_mode` zA. Only `reflect`, `wrap`, `constant` and `nearest` are supported.>   r   bilinearzUnknown `interpolation` z.. Only `nearest` and `bilinear` are supported.)NotImplementedError)	fill_modeinterpolations     o/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/preprocessing/image_preprocessing.py!check_fill_mode_and_interpolationr      sW    BB!"9+ .6 6
 	
 33!&}o 6( (
 	
 4    zkeras.layers.Resizingz0keras.layers.experimental.preprocessing.Resizingc                   L   ^  \ 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
$ )	Resizing,   a  A preprocessing layer which resizes images.

This layer resizes an image input to a target height and width. The input
should be a 4D (batched) or 3D (unbatched) tensor in `"channels_last"`
format. 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.

This layer can be called on tf.RaggedTensor batches of input images of
distinct sizes, and will resize the outputs to dense tensors of uniform
size.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

Args:
    height: Integer, the height of the output shape.
    width: Integer, the width of the output shape.
    interpolation: String, the interpolation method.
        Supports `"bilinear"`, `"nearest"`, `"bicubic"`, `"area"`,
        `"lanczos3"`, `"lanczos5"`, `"gaussian"`, `"mitchellcubic"`.
        Defaults to `"bilinear"`.
    crop_to_aspect_ratio: If True, resize the images without aspect
        ratio distortion. When the original aspect ratio differs
        from the target aspect ratio, the output image will be
        cropped so as to return the
        largest possible window in the image (of size `(height, width)`)
        that matches the target aspect ratio. By default
        (`crop_to_aspect_ratio=False`), aspect ratio may not be preserved.
c                    > Xl         X l        X0l        X@l        [        R
                  " U5      U l        [        TU ]   " S0 UD6  g N )	heightwidthr   crop_to_aspect_ratior   get_interpolation_interpolation_methodsuper__init__)selfr   r   r   r   kwargs	__class__s         r   r#   Resizing.__init__O   sC     
*$8!%0%B%B&
" 	"6"r   c                 ^  ^ ^^ T R                   S:X  a  T R                  nO[        R                  n[	        TUS9mT R
                  T R                  /mT R                  (       a  UU U4S jn[        R                  " T5      (       aU  [        R                  " T5      nUTR                  SS  -   n[        R                  " XR5      n[        R                  " UTUS9nO2U" T5      nO)[        R                  R                  TTT R                   S9n[        R"                  " UT R                  5      $ )Nr   dtypec                    > [         R                  " T5      (       a  U R                  5       n [        R                  " U TTR
                  S9$ )N)sizer   )r   	is_ragged	to_tensorr   smart_resizer!   )xinputsr$   r,   s    r   resize_to_aspect'Resizing.call.<locals>.resize_to_aspectm   s?    %%f--A"//D0J0J r   )fn_output_signature)r,   method)r   compute_dtypetffloat32convert_inputsr   r   r   r   r-   TensorShapeshape
TensorSpecmap_fnimageresizer!   cast)	r$   r1   input_dtyper2   size_as_shaper<   specoutputsr,   s	   ``      @r   callResizing.call`   s    
 *,,K**Kk:TZZ($$ !!&)) "t 4%RS(99}}U8))$f$ +62hhooT$*D*D & G www 2 233r   c                     [         R                  " U5      R                  5       nU R                  U[        '   U R
                  U[        '   [         R                  " U5      $ Nr8   r;   as_listr   H_AXISr   W_AXISr$   input_shapes     r   compute_output_shapeResizing.compute_output_shape   D    nn[199;"kkF"jjF~~k**r   c                    > U R                   U R                  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   r   r   r   r"   
get_configdictlistitemsr$   configbase_configr&   s      r   rT   Resizing.get_config   sb    kkZZ!//$($=$=	
 g(*D**,-V\\^0DDEEr   )r!   r   r   r   r   )r   F__name__
__module____qualname____firstlineno____doc__r#   rF   rP   rT   __static_attributes____classcell__r&   s   @r   r   r   ,   s-    F !"#"!4F+F Fr   r   zkeras.layers.CenterCropz2keras.layers.experimental.preprocessing.CenterCropc                   D   ^  \ rS rSrSrU 4S jrS rS rU 4S jrSr	U =r
$ )
CenterCrop   a=  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]`) and
of integer or floating point dtype.
By default, the layer will output floats.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

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

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

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.

Args:
    height: Integer, the height of the output shape.
    width: Integer, the width of the output shape.
c                 F   > Xl         X l        [        TU ]  " S0 UDSS0D6  g )NautocastFr   )r   r   r"   r#   )r$   r   r   r%   r&   s       r   r#   CenterCrop.__init__   s"    
262E2r   c                 @  ^ ^^^ [        TT R                  5      m[        R                  " T5      nU[           T R
                  -
  mU[           T R                  -
  mUUU U4S jnUU 4S jn[        R                  " [        R                  " TS:  TS:  45      X45      $ )Nc                    > [         R                  " TS-  [         R                  5      n [         R                  " TS-  [         R                  5      n[         R                  R	                  TXTR
                  TR                  5      $ )N   )r8   rA   int32r?   crop_to_bounding_boxr   r   )h_startw_starth_diffr1   r$   w_diffs     r   center_crop$CenterCrop.call.<locals>.center_crop   s[    ggfqj"((3Gggfqj"((3G8800$++tzz r   c                     > [         R                  " TTR                  TR                  /5      n [        R
                  " U TR                  5      $ rI   r   r/   r   r   r8   rA   r7   rE   r1   r$   s    r   upsizeCenterCrop.call.<locals>.upsize   >    !..djj1G 777D$6$677r   r   
r:   r7   r8   r<   rL   r   rM   r   cond
reduce_all)r$   r1   rO   rt   ry   rr   rs   s   ``   @@r   rF   CenterCrop.call   s    (:(:;hhv&V$t{{2V$tzz1	 		8 wwMM6Q;!45{
 	
r   c                     [         R                  " U5      R                  5       nU R                  U[        '   U R
                  U[        '   [         R                  " U5      $ rI   rJ   rN   s     r   rP   CenterCrop.compute_output_shape   rR   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"   rT   rU   rV   rW   rX   s      r   rT   CenterCrop.get_config   sP    kkZZ
 g(*D**,-V\\^0DDEEr   r   r\   rd   s   @r   rf   rf      s#    
<3

0+F Fr   rf   zkeras.layers.RandomCropz2keras.layers.experimental.preprocessing.RandomCrop)v1c                   L   ^  \ rS rSrSrSU 4S jjrS	S jrS rU 4S jrSr	U =r
$ )

RandomCrop   a  A preprocessing layer which randomly crops images during training.

During training, this layer will randomly choose a location to crop images
down to a target size. The layer will crop all the images in the same batch
to the same cropping location.

At inference time, and during training if an input image is smaller than the
target size, the input will be resized and cropped so as to return the
largest possible window in the image that matches the target aspect ratio.
If you need to apply random cropping at inference time, set `training` to
True when calling the layer.

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.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

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

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

Args:
    height: Integer, the height of the output shape.
    width: Integer, the width of the output shape.
    seed: Integer. Used to create a random seed.
c                 V   > [         TU ]  " S0 UDSUSS.D6  Xl        X l        X0l        g )NFT)ri   seedforce_generatorr   )r"   r#   r   r   r   )r$   r   r   r   r%   r&   s        r   r#   RandomCrop.__init__
  s5     	
	
$4	
 
	r   c                 D  ^ ^^^^ [        TT R                  S9m[        R                  " T5      mT[           T R
                  -
  mT[           T R                  -
  mUUUU U4S jnUU 4S jn[        R                  " [        R                  " UTS:  TS:  45      UU5      $ )Nr)   c                    > TR                   n TR                  R                  S/SU R                  U 5      nUS   TS-   -  nUS   TS-   -  n[        R
                  R                  TX#TR                  TR                  5      $ )Nrm   r      )	r*   _random_generatorrandom_uniformmaxr8   r?   ro   r   r   )	r*   randsrp   rq   rr   rO   r1   r$   rs   s	       r   random_crop$RandomCrop.call.<locals>.random_crop  s    %%E**99Q		5E Ah&1*-GAh&1*-G8800$++tzz r   c                     > [         R                  " TTR                  TR                  /5      n [        R
                  " U TR                  5      $ rI   rw   rx   s    r   r@   RandomCrop.call.<locals>.resize#  r{   r   r   r|   )r$   r1   trainingr   r@   rr   rO   rs   s   ``   @@@r   rF   RandomCrop.call  s    d.@.@Ahhv&V$t{{2V$tzz1		 			8 wwMM8Vq[&A+>?
 	
r   c                     [         R                  " U5      R                  5       nU R                  U[        '   U R
                  U[        '   [         R                  " U5      $ rI   rJ   rN   s     r   rP   RandomCrop.compute_output_shape0  rR   r   c                    > U R                   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   r   r"   rT   rU   rV   rW   rX   s      r   rT   RandomCrop.get_config6  sW    kkZZII

 g(*D**,-V\\^0DDEEr   )r   r   r   rI   Tr\   rd   s   @r   r   r      s$    B
<+F Fr   r   zkeras.layers.Rescalingz1keras.layers.experimental.preprocessing.Rescalingc                   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
$ )		Rescalingi@  a  A preprocessing layer which rescales input values to a new range.

This layer rescales every value of an input (often an image) by multiplying
by `scale` and adding `offset`.

For instance:

1. To rescale an input in the `[0, 255]` range
to be in the `[0, 1]` range, you would pass `scale=1./255`.

2. To rescale an input in the `[0, 255]` range to be in the `[-1, 1]` range,
you would pass `scale=1./127.5, offset=-1`.

The rescaling is applied both during training and inference. Inputs can be
of integer or floating point dtype, and by default the layer will output
floats.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

Input shape:
    Arbitrary.

Output shape:
    Same as input.

Args:
    scale: Float, the scale to apply to the inputs.
    offset: Float, the offset to apply to the inputs.
c                 >   > Xl         X l        [        TU ]  " S0 UD6  g r   )scaleoffsetr"   r#   )r$   r   r   r%   r&   s       r   r#   Rescaling.__init__d  s    
"6"r   c                     U R                   n[        XS9n[        R                  " U R                  U5      n[        R                  " U R
                  U5      n[        R                  " X5      U-  U-   $ Nr)   )r7   r:   r8   rA   r   r   )r$   r1   r*   r   r   s        r   rF   Rescaling.calli  sX    ""4

E*e,wwv%-66r   c                     U$ rI   r   rN   s     r   rP   Rescaling.compute_output_shapep      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"   rT   rU   rV   rW   rX   s      r   rT   Rescaling.get_configs  sP    ZZkk
 g(*D**,-V\\^0DDEEr   )r   r   )        r\   rd   s   @r   r   r   @  s#    
>#
7F Fr   r   
horizontalverticalhorizontal_and_verticalzkeras.layers.RandomFlipz2keras.layers.experimental.preprocessing.RandomFlipc                   P   ^  \ rS rSrSr\S4U 4S jjrS	S jrS rU 4S jr	Sr
U =r$ )

RandomFlipi  a  A preprocessing layer which randomly flips images during training.

This layer will flip the images horizontally and or vertically based on the
`mode` attribute. During inference time, the output will be identical to
input. Call the layer with `training=True` to flip the input.

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.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

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

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

Args:
    mode: String indicating which flip mode to use. Can be `"horizontal"`,
        `"vertical"`, or `"horizontal_and_vertical"`. `"horizontal"` is a
        left-right flip and `"vertical"` is a top-bottom flip. Defaults to
        `"horizontal_and_vertical"`
    seed: Integer. Used to create a random seed.
Nc                   > [         TU ]  " SUSS.UD6  Xl        U[        :X  a  SU l        SU l        OMU[        :X  a  SU l        SU l        O4U[        :X  a  SU l        SU l        O[        SU R                   SU 35      eX l
        g )NTr   r   FzRandomFlip layer z# received an unknown mode argument r   )r"   r#   mode
HORIZONTALr   r   VERTICALHORIZONTAL_AND_VERTICAL
ValueErrornamer   )r$   r   r   r%   r&   s       r   r#   RandomFlip.__init__  s    CdDCFC	:"DO!DMX#DO DM,,"DO DM#DII; / 6#  	r   c                 ^   ^  [        UT R                  5      nU 4S jnU(       a  U" U5      $ U$ )Nc                 R  > U nTR                   (       as  TR                  R                  5       nUb  [        R                  R                  XS9nO8[        R                  R                  UTR                  R                  5       5      nTR                  (       as  TR                  R                  5       nUb  [        R                  R                  XS9nO8[        R                  R                  UTR                  R                  5       5      nUR                  U R                  5        U$ )Nr   )r   r   make_seed_for_stateless_opr8   r?    stateless_random_flip_left_rightrandom_flip_left_rightmake_legacy_seedr   stateless_random_flip_up_downrandom_flip_up_down	set_shaper<   )r1   flipped_outputsr   r$   s      r   random_flipped_inputs.RandomFlip.call.<locals>.random_flipped_inputs  s    $O--HHJ#&(hh&O&O' 'P 'O ')hh&E&E'..??A'O }}--HHJ#&(hh&L&L' 'M 'O ')hh&B&B'..??A'O %%fll3""r   r:   r7   )r$   r1   r   r   s   `   r   rF   RandomFlip.call  s/    (:(:;	#6 (00Mr   c                     U$ rI   r   rN   s     r   rP   RandomFlip.compute_output_shape  r   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"   rT   rU   rV   rW   rX   s      r   rT   RandomFlip.get_config  sP    IIII
 g(*D**,-V\\^0DDEEr   )r   r   r   r   r   )r]   r^   r_   r`   ra   r   r#   rF   rP   rT   rb   rc   rd   s   @r   r   r     s+    : 4$ &!FF Fr   r   zkeras.layers.RandomTranslationz9keras.layers.experimental.preprocessing.RandomTranslationc                   T   ^  \ rS rSrSr    SU 4S jjrS	S jrS rU 4S jrSr	U =r
$ )
RandomTranslationi  a;  A preprocessing layer which randomly translates images during training.

This layer will apply random translations to each image during training,
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.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

Args:
  height_factor: a float represented as fraction of value, or a tuple of
      size 2 representing lower and upper bound for shifting vertically. A
      negative value means shifting image up, while a positive value means
      shifting image down. When represented as a single positive float, this
      value is used for both the upper and lower bound. For instance,
      `height_factor=(-0.2, 0.3)` results in an output shifted by a random
      amount in the range `[-20%, +30%]`.  `height_factor=0.2` results in an
      output height shifted by a random amount in the range `[-20%, +20%]`.
  width_factor: a float represented as fraction of value, or a tuple of size
      2 representing lower and upper bound for shifting horizontally. A
      negative value means shifting image left, while a positive value means
      shifting image right. When represented as a single positive float,
      this value is used for both the upper and lower bound. For instance,
      `width_factor=(-0.2, 0.3)` results in an output shifted left by 20%,
      and shifted right by 30%. `width_factor=0.2` results
      in an output height shifted left or right by 20%.
  fill_mode: Points outside the boundaries of the input are filled according
      to the given mode
      (one of `{"constant", "reflect", "wrap", "nearest"}`).
      - *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 = 0.
      - *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.
  interpolation: Interpolation mode. Supported values: `"nearest"`,
      `"bilinear"`.
  seed: Integer. Used to create a random seed.
  fill_value: a float represents the value to be filled outside the
      boundaries when `fill_mode="constant"`.

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

Output shape:
    3D (unbatched) or 4D (batched) tensor with shape:
    `(..., height, width, channels)`,  in `"channels_last"` format.
c                 "  > [         TU ]  " S
USS.UD6  Xl        [        U[        [
        45      (       a  US   U l        US   U l        OU* U l        Xl        U R                  U R                  :  a  [        SU 35      e[        U R                  5      S:  d  [        U R                  5      S:  a  [        SU 35      eX l
        [        U[        [
        45      (       a  US   U l        US   U l        OU* U l        X l        U R                  U R                  :  a  [        SU 35      e[        U R                  5      S:  d  [        U R                  5      S:  a  [        S	U 35      e[        X45        X0l        X`l        X@l        XPl        g )NTr   r   r   zC`height_factor` cannot have upper bound less than lower bound, got       ?S`height_factor` argument must have values between [-1, 1]. Received: height_factor=zB`width_factor` cannot have upper bound less than lower bound, got z5`width_factor` must have values between [-1, 1], got r   )r"   r#   height_factor
isinstancetuplerV   height_lowerheight_upperr   abswidth_factorwidth_lowerwidth_upperr   r   
fill_valuer   r   	r$   r   r   r   r   r   r   r%   r&   s	           r   r#   RandomTranslation.__init__%  s    	CdDCFC*meT]33 -a 0D -a 0D!.D -t000$$1?4  t  !C'3t/@/@+AC+G++8/; 
 )lUDM22+AD+AD ,}D+d...$$0>3  t 3&#d.>.>*?#*E#n& 
 	*)C"$*	r   c                 ^   ^  [        UT R                  5      nU 4S jnU(       a  U" U5      $ U$ )Nc                   > U R                   nU R                   R                  S:H  nU(       a  [        R                  " U S5      n [        R                   " U 5      nUS   n[        R                  " U[
           [        R                  5      n[        R                  " U[           [        R                  5      nTR                  R                  US/TR                  TR                  [        R                  S9nXu-  nTR                  R                  US/TR                  TR                  [        R                  S9nX-  n[        R                  " [        R                  " X/SS9[        R                  S9n	[        U [!        U	5      TR"                  TR$                  TR&                  S9n
U(       a  [        R(                  " U
S5      n
U
R+                  U5        U
$ )z"Translated inputs with random ops.   r   r   )r<   minvalmaxvalr*   axisr)   )r   r   r   )r<   rankr8   expand_dimsrA   rL   r9   rM   r   r   r   r   r   r   concat	transformget_translation_matrixr   r   r   squeezer   )r1   original_shape	unbatchedinputs_shape
batch_sizeimg_hdimg_wdheight_translatewidth_translatetranslationsoutputr$   s              r   random_translated_inputs8RandomTranslation.call.<locals>.random_translated_inputs^  s   
 $\\N))Q.I288F+L%aJWW\&12::>FWW\&12::>F#55DD!1o((((jj	  E    08"44CC!1o''''jj	 D O .6O77		?=AFjjL &|4"00..??F FA.^,Mr   r   )r$   r1   r   r   s   `   r   rF   RandomTranslation.call[  s0    (:(:;*	X +F33Mr   c                     U$ rI   r   rN   s     r   rP   &RandomTranslation.compute_output_shape  r   r   c                 "  > U R                   U R                  U R                  U R                  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   r   r   r   r   r   r   r   r"   rT   rU   rV   rW   rX   s      r   rT   RandomTranslation.get_config  r    !// --//!//II
 g(*D**,-V\\^0DDEEr   
r   r   r   r   r   r   r   r   r   r   r   r   Nr   r   r\   rd   s   @r   r   r     s4    6x  4l2h
F 
Fr   r   c                 v   [         R                  " U=(       d    S5         [        R                  " U 5      S   n[        R                  " [        R
                  " US4[        R                  5      [        R                  " US4[        R                  5      U SS2SS4   * [        R                  " US4[        R                  5      [        R
                  " US4[        R                  5      U SS2SS4   * [        R                  " US4[        R                  5      /SS9sSSS5        $ ! , (       d  f       g= f)aY  Returns projective transform(s) for the given translation(s).

Args:
    translations: A matrix of 2-element lists representing `[dx, dy]`
        to translate for each image (for a batch of images).
    name: The name of the op.

Returns:
    A tensor of shape `(num_images, 8)` projective transforms
        which can be given to `transform`.
translation_matrixr   r   Nrm   valuesr   )r   
name_scoper8   r<   r   onesr9   zeros)r   r   num_translationss      r   r   r     s     
		D8$8	988L1!4 yy)1-rzz:*A.

;aDj))*A.

;)1-rzz:aDj))*A.

; 
 
:	9	9s   D D**
D8c           
         [         R                  " U=(       d    S5         UcN  [        R                  " U 5      SS n[        R                  " 5       (       d  [        R
                  " U5      nUb  Un[        R                  " U[        R                  SS9nUR                  5       R                  S/5      (       d  [        SU 35      e[        R                  " U[        R                  S	S9n[        R                  R                  U UUUUR                  5       UR                  5       S
9sSSS5        $ ! , (       d  f       g= f)a  Applies the given transform(s) to the image(s).

Args:
    images: A tensor of shape
        `(num_images, num_rows, num_columns, num_channels)` (NHWC).
        The rank must be statically known
        (the shape is not `TensorShape(None)`).
    transforms: Projective transform matrix/matrices.
        A vector of length 8 or tensor of size N x 8.
        If one row of transforms is [a0, a1, a2, b0, b1, b2,
        c0, c1], then it maps the *output* point `(x, y)`
        to a transformed *input* point
        `(x', y') = ((a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k)`, where
        `k = c0 x + c1 y + 1`. The transforms are *inverted* compared to the
        transform mapping input points to output points.
        Note that gradients are not backpropagated
        into transformation parameters.
    fill_mode: Points outside the boundaries of the input are filled
        according to the given mode
        (one of `{"constant", "reflect", "wrap", "nearest"}`).
    fill_value: a float represents the value to be filled outside
        the boundaries when `fill_mode="constant"`.
    interpolation: Interpolation mode. Supported values: `"nearest"`,
        `"bilinear"`.
    output_shape: Output dimension after the transform, `[height, width]`.
        If `None`, output is the same size as input image.
    name: The name of the op.

Fill mode behavior for each valid value is as follows:

- `"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 = 0.

- `"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.

Input shape:
    4D tensor with shape: `(samples, height, width, channels)`,
        in `"channels_last"` format.

Output shape:
    4D tensor with shape: `(samples, height, width, channels)`,
        in `"channels_last"` format.

Returns:
    Image(s) with the same type and shape as `images`, with the given
    transform(s) applied. Transformed coordinates outside of the input image
    will be filled with zeros.
r   Nr   r   output_shape)r   rm   zaoutput_shape must be a 1-D Tensor of 2 elements: new_height, new_width, instead got output_shape=r   )imagesr  r   
transformsr   r   )r   r  r8   r<   executing_eagerlyget_static_valueconvert_to_tensorrn   	get_shapeis_compatible_withr   r9   raw_opsImageProjectiveTransformV3upper)r  r  r   r   r   r  r   output_shape_values           r   r   r     s   B 
		D/K	088F+Aa0L''))%'%8%8%F"%1#5L++"((
 %%'::A3??  ,~/  ))



 zz44%!!oo''--/ 5 
/ 
1	0	0s   D
D44
Ec                 (   [         R                  " U=(       d    S5         US-
  [        R                  " U 5      US-
  -  [        R                  " U 5      US-
  -  -
  -
  S-  nUS-
  [        R                  " U 5      US-
  -  [        R                  " U 5      US-
  -  -   -
  S-  n[        R
                  " U 5      S   n[        R                  " [        R                  " U 5      SS2S4   [        R                  " U 5      SS2S4   * USS2S4   [        R                  " U 5      SS2S4   [        R                  " U 5      SS2S4   USS2S4   [        R                  " US4[        R                  5      /SS9sSSS5        $ ! , (       d  f       g= f)a`  Returns projective transform(s) for the given angle(s).

Args:
    angles: A scalar angle to rotate all images by,
        or (for batches of images) a vector with an angle to
        rotate each image in the batch. The rank must be
        statically known (the shape is not `TensorShape(None)`).
    image_height: Height of the image(s) to be transformed.
    image_width: Width of the image(s) to be transformed.
    name: The name of the op.

Returns:
    A tensor of shape (num_images, 8).
        Projective transforms which can be given
        to operation `image_projective_transform_v2`.
        If one row of transforms is
        [a0, a1, a2, b0, b1, b2, c0, c1], then it maps the *output* point
        `(x, y)` to a transformed *input* point
        `(x', y') = ((a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k)`,
        where `k = c0 x + c1 y + 1`.
rotation_matrixr          @r   Nrm   r  )	r   r  r8   cossinr<   r   r	  r9   )anglesimage_heightimage_widthr   x_offsety_offset
num_angless          r   get_rotation_matrixr#  #  s_   , 
		D5$5	61_v+/2&&.L1$456
  Av+/2&&.L1$456
  XXf%a(
yyvq$w'4((D!vq$w'vq$w'D!*a"**5 
! 
7	6	6s   EF
Fzkeras.layers.RandomRotationz6keras.layers.experimental.preprocessing.RandomRotationc                   T   ^  \ rS rSrSr    SU 4S jjrS	S jrS rU 4S jrSr	U =r
$ )
RandomRotationiW  a:
  A preprocessing layer which randomly rotates images during training.

This layer will apply random rotations to each image, filling empty space
according to `fill_mode`.

By default, random rotations are only applied during training.
At inference time, the layer does nothing. If you need to apply random
rotations at inference time, set `training` to True when calling the layer.

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.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

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

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

Args:
    factor: a float represented as fraction of 2 Pi, or a tuple of size 2
        representing lower and upper bound for rotating clockwise and
        counter-clockwise. A positive values means rotating
        counter clock-wise,
        while a negative value means clock-wise.
        When represented as a single
        float, this value is used for both the upper and lower bound.
        For instance, `factor=(-0.2, 0.3)`
        results in an output rotation by a random
        amount in the range `[-20% * 2pi, 30% * 2pi]`.
        `factor=0.2` results in an
        output rotating by a random amount
        in the range `[-20% * 2pi, 20% * 2pi]`.
    fill_mode: Points outside the boundaries of the input are filled
        according to the given mode
        (one of `{"constant", "reflect", "wrap", "nearest"}`).
        - *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 = 0.
        - *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.
    interpolation: Interpolation mode. Supported values: `"nearest"`,
        `"bilinear"`.
    seed: Integer. Used to create a random seed.
    fill_value: a float represents the value to be filled outside
        the boundaries when `fill_mode="constant"`.
c                 J  > [         TU ]  " SUSS.UD6  Xl        [        U[        [
        45      (       a  US   U l        US   U l        OU* U l        Xl        U R                  U R                  :  a  [        SU 35      e[        X#5        X l
        XPl        X0l        X@l        g )NTr   r   r   zA`factor` argument cannot have a negative value. Received: factor=r   )r"   r#   factorr   r   rV   lowerr  r   r   r   r   r   r   )r$   r'  r   r   r   r   r%   r&   s          r   r#   RandomRotation.__init__  s     	CdDCFCfudm,,DJDJ DJJ::

"$$*8-  	*)C"$*	r   c                 ^   ^  [        UT R                  5      nU 4S jnU(       a  U" U5      $ U$ )Nc                   > U R                   nU R                   R                  S:H  nU(       a  [        R                  " U S5      n [        R                   " U 5      nUS   n[        R                  " U[
           [        R                  5      n[        R                  " U[           [        R                  5      nTR                  S-  [        R                  -  nTR                  S-  [        R                  -  nTR                  R                  U/XxS9n	[        U [        XU5      TR                   TR"                  TR$                  S9n
U(       a  [        R&                  " U
S5      n
U
R)                  U5        U
$ )zRotated inputs with random ops.r   r   r  r<   r   r   r   r   r   )r<   r   r8   r   rA   rL   r9   rM   r(  nppir  r   r   r   r#  r   r   r   r   r   )r1   r   r   r   r   r   r   	min_angle	max_angler  r   r$   s              r   random_rotated_inputs2RandomRotation.call.<locals>.random_rotated_inputs  s&   #\\N))Q.I 288F+L%aJWW\&12::>FWW\&12::>F

S(2550I

S(2550I++::!l9 ; F #FF;..??"00F FA.^,Mr   r   )r$   r1   r   r2  s   `   r   rF   RandomRotation.call  s/    (:(:;	< (00Mr   c                     U$ rI   r   rN   s     r   rP   #RandomRotation.compute_output_shape  r   r   c                   > U R                   U R                  U R                  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   )
r'  r   r   r   r   r"   rT   rU   rV   rW   rX   s      r   rT   RandomRotation.get_config  sg    kk//!//II
 g(*D**,-V\\^0DDEEr   )r'  r   r   r   r(  r   r  r  r   r\   rd   s   @r   r%  r%  W  s3    9|  8$L	F 	Fr   r%  zkeras.layers.RandomZoomz2keras.layers.experimental.preprocessing.RandomZoomc                   V   ^  \ rS rSrSr     SU 4S jjrS	S jrS rU 4S jrSr	U =r
$ )

RandomZoomi  ac  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.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

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
        (one of `{"constant", "reflect", "wrap", "nearest"}`).
        - *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 = 0.
        - *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.
    interpolation: Interpolation mode. Supported values: `"nearest"`,
        `"bilinear"`.
    seed: Integer. Used to create a random seed.
    fill_value: a float represents the value to be filled outside
        the boundaries when `fill_mode="constant"`.

Example:

>>> input_img = np.random.random((32, 224, 224, 3))
>>> layer = tf.keras.layers.RandomZoom(.5, .2)
>>> out_img = layer(input_img)
>>> out_img.shape
TensorShape([32, 224, 224, 3])

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

Output shape:
    3D (unbatched) or 4D (batched) tensor with shape:
    `(..., height, width, channels)`, in `"channels_last"` format.
c                 d  > [         TU ]  " S	USS.UD6  Xl        [        U[        [
        45      (       a  US   U l        US   U l        OU* U l        Xl        [        U R                  5      S:  d  [        U R                  5      S:  a  [        SU 35      eX l
        Ubl  [        U[        [
        45      (       a  US   U l        US   U l        OU* U l        X l        U R                  S:  d  U R                  S:  a  [        SU 35      e[        X45        X0l        X`l        X@l        XPl        g )
NTr   r   r   r   r         zP`width_factor` argument must have values larger than -1. Received: width_factor=r   )r"   r#   r   r   r   rV   r   r   r   r   r   r   r   r   r   r   r   r   r   s	           r   r#   RandomZoom.__init__7  s;    	CdDCFC*meT]33 -a 0D -a 0D!.D -t  !C'3t/@/@+AC+G++8/; 
 )#,66#/? #/? $0= #/ $&$*:*:T*A ..:^= 
 	*)C"$*	r   c                 ^   ^  [        UT R                  5      nU 4S jnU(       a  U" U5      $ U$ )Nc                   > U R                   nU R                   R                  S:H  nU(       a  [        R                  " U S5      n [        R                   " U 5      nUS   n[        R                  " U[
           [        R                  5      n[        R                  " U[           [        R                  5      nTR                  R                  US/STR                  -   STR                  -   S9nTR                  b8  TR                  R                  US/STR                  -   STR                  -   S9nOUn[        R                  " [        R                  " X/SS9[        R                  S9n	[!        U [#        XU5      TR$                  TR&                  TR(                  S9n
U(       a  [        R*                  " U
S5      n
U
R-                  U5        U
$ )	zZoomed inputs with random ops.r   r   r   r   r,  r   r)   r-  )r<   r   r8   r   rA   rL   r9   rM   r   r   r   r   r   r   r   r   r   get_zoom_matrixr   r   r   r   r   )r1   r   r   r   r   r   r   height_zoom
width_zoomzoomsr   r$   s              r   random_zoomed_inputs-RandomZoom.call.<locals>.random_zoomed_inputsi  s   #\\N))Q.I 288F+L%aJWW\&12::>FWW\&12::>F00??!1oT...T... @ K
   ,!33BB%q/!1!11!1!11 C 
 )
GG		:3!<BJJE v6..??"00F FA.^,Mr   r   )r$   r1   r   rD  s   `   r   rF   RandomZoom.callf  s0    (:(:;'	R '//Mr   c                     U$ rI   r   rN   s     r   rP   RandomZoom.compute_output_shape  r   r   c                 "  > U R                   U R                  U R                  U R                  U R                  U R
                  S.n[        TU ]  5       n[        [        UR                  5       5      [        UR                  5       5      -   5      $ r   r   rX   s      r   rT   RandomZoom.get_config  r   r   r  )Nr   r   Nr   r   r\   rd   s   @r   r:  r:    s8    FV  -^/b
F 
Fr   r:  c                 6   [         R                  " U=(       d    S5         [        R                  " U 5      S   nUS-
  S-  SU SS2SS4   -
  -  nUS-
  S-  SU SS2SS4   -
  -  n[        R                  " U SS2SS4   [        R
                  " US4[        R                  5      U[        R
                  " US4[        R                  5      U SS2SS4   U[        R
                  " US4[        R                  5      /SS9sSSS5        $ ! , (       d  f       g= f)	a  Returns projective transform(s) for the given zoom(s).

Args:
    zooms: A matrix of 2-element lists representing `[zx, zy]`
        to zoom for each image (for a batch of images).
    image_height: Height of the image(s) to be transformed.
    image_width: Width of the image(s) to be transformed.
    name: The name of the op.

Returns:
    A tensor of shape `(num_images, 8)`. Projective transforms which can be
        given to operation `image_projective_transform_v2`.
        If one row of transforms is
        `[a0, a1, a2, b0, b1, b2, c0, c1]`, then it maps the *output* point
        `(x, y)` to a transformed *input* point
        `(x', y') = ((a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k)`,
        where `k = c0 x + c1 y + 1`.
zoom_matrixr   r   r  Nr   rm   r  )r   r  r8   r<   r   r	  r9   )rC  r  r  r   	num_zoomsr   r!  s          r   r@  r@    s    & 
		D1M	2HHUOA&	 !3&#-#aDj8I2IJ!C'3.3q!Tz9J3JKyyaDj!)Q4)Q4aDj!)Q4 
 
3	2	2s   C D


Dzkeras.layers.RandomContrastz6keras.layers.experimental.preprocessing.RandomContrastc                   L   ^  \ rS rSrSrSU 4S jjrS	S jrS rU 4S jrSr	U =r
$ )
RandomContrasti  a  A preprocessing layer which randomly adjusts contrast during training.

This layer will randomly adjust the contrast of an image or images
by a random factor. Contrast is adjusted independently
for each channel of each image during training.

For each channel, this layer computes the mean of the image pixels in the
channel and then adjusts each component `x` of each pixel to
`(x - mean) * contrast_factor + mean`.

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

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

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

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

Args:
    factor: a positive float represented as fraction of value, or a tuple of
        size 2 representing lower and upper bound.
        When represented as a single float, lower = upper.
        The contrast factor will be randomly picked between
        `[1.0 - lower, 1.0 + upper]`. For any pixel x in the channel,
        the output will be `(x - mean) * factor + mean`
        where `mean` is the mean value of the channel.
    seed: Integer. Used to create a random seed.
c                 <  > [         TU ]  " SUSS.UD6  Xl        [        U[        [
        45      (       a  US   U l        US   U l        OU=U l        U l        U R                  S:  d   U R                  S:  d  U R                  S:  a  [        SU 35      eX l	        g )	NTr   r   r   r   r   zX`factor` argument cannot have negative values or values greater than 1.Received: factor=r   )
r"   r#   r'  r   r   rV   r(  r  r   r   )r$   r'  r   r%   r&   s       r   r#   RandomContrast.__init__  s    CdDCFCfudm,,DJDJ&,,DJ::tzzC/4::3C$$*8- 
 	r   c                 ^   ^  [        UT R                  5      nU 4S jnU(       a  U" U5      $ U$ )Nc                   > TR                   R                  5       nUb;  [        R                  R	                  U STR
                  -
  STR                  -   US9nOR[        R                  R                  U STR
                  -
  STR                  -   TR                   R                  5       S9n[        R                  " USS5      nUR                  U R                  5        U$ )Nr   r   r      )r   r   r8   r?   stateless_random_contrastr(  r  random_contrastr   clip_by_valuer   r<   )r1   r   r   r$   s      r   random_contrasted_inputs5RandomContrast.call.<locals>.random_contrasted_inputs  s    ))DDFD;;C$**,cDJJ.>T <  11$**$$**$//@@B	 2  %%fa5FV\\*Mr   r   )r$   r1   r   rX  s   `   r   rF   RandomContrast.call  s/    (:(:;	" +F33Mr   c                     U$ rI   r   rN   s     r   rP   #RandomContrast.compute_output_shape'  r   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"   rT   rU   rV   rW   rX   s      r   rT   RandomContrast.get_config*  sP    kkII
 g(*D**,-V\\^0DDEEr   )r'  r(  r   r  rI   r   r\   rd   s   @r   rO  rO    s$    $L 2F Fr   rO  zkeras.layers.RandomBrightnessc                   f   ^  \ rS rSrSrSrSrSU 4S jjrS rS r	S r
SS	 jrS
 rU 4S jrSrU =r$ )RandomBrightnessi3  a	  A preprocessing layer which randomly adjusts brightness during training.

This layer will randomly increase/reduce the brightness for the input RGB
images. At inference time, the output will be identical to the input.
Call the layer with `training=True` to adjust the brightness of the input.

Note that different brightness adjustment factors
will be apply to each the images in the batch.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

Args:
    factor: Float or a list/tuple of 2 floats between -1.0 and 1.0. The
        factor is used to determine the lower bound and upper bound of the
        brightness adjustment. A float value will be chosen randomly between
        the limits. When -1.0 is chosen, the output image will be black, and
        when 1.0 is chosen, the image will be fully white.
        When only one float is provided, eg, 0.2,
        then -0.2 will be used for lower bound and 0.2
        will be used for upper bound.
    value_range: Optional list/tuple of 2 floats
        for the lower and upper limit
        of the values of the input data.
        To make no change, use [0.0, 1.0], e.g., if the image input
        has been scaled before this layer. Defaults to [0.0, 255.0].
        The brightness adjustment will be scaled to this range, and the
        output values will be clipped to this range.
    seed: optional integer, for fixed RNG behavior.

Inputs: 3D (HWC) or 4D (NHWC) tensor, with float or int dtype. Input pixel
    values can be of any range (e.g. `[0., 1.)` or `[0, 255]`)

Output: 3D (HWC) or 4D (NHWC) tensor with brightness adjusted based on the
    `factor`. By default, the layer will output floats.
    The output value will be clipped to the range `[0, 255]`,
    the valid range of RGB colors, and
    rescaled based on the `value_range` if needed.

Sample usage:

```python
random_bright = tf.keras.layers.RandomBrightness(factor=0.2)

# An image with shape [2, 2, 3]
image = [[[1, 2, 3], [4 ,5 ,6]], [[7, 8, 9], [10, 11, 12]]]

# Assume we randomly select the factor to be 0.1, then it will apply
# 0.1 * 255 to all the channel
output = random_bright(image, training=True)

# output will be int64 with 25.5 added to each channel and round down.
tf.Tensor([[[26.5, 27.5, 28.5]
            [29.5, 30.5, 31.5]]
           [[32.5, 33.5, 34.5]
            [35.5, 36.5, 37.5]]],
          shape=(2, 2, 3), dtype=int64)
```
z^The `factor` argument should be a number (or a list of two numbers) in the range [-1.0, 1.0]. z<The `value_range` argument should be a list of two numbers. c                 |   > [         TU ]  " SUSS.UD6  U R                  U5        U R                  U5        X0l        g )NTr   r   )r"   r#   _set_factor_set_value_range_seed)r$   r'  value_ranger   r%   r&   s        r   r#   RandomBrightness.__init__y  s;    CdDCFC k*
r   c                     [        U[        [        45      (       d  [        U R                  SU 3-   5      e[        U5      S:w  a  [        U R                  SU 3-   5      e[        U5      U l        g )NGot rm   )r   r   rV   r   _VALUE_RANGE_VALIDATION_ERRORlensorted_value_range)r$   re  s     r   rc  !RandomBrightness._set_value_range  su    +t}5522tK=5II  {q 22tK=5II  #;/r   c                    [        U[        [        45      (       ac  [        U5      S:w  a  [	        U R
                  SU 3-   5      eU R                  US   5        U R                  US   5        [        U5      U l        g [        U[        [        45      (       a'  U R                  U5        [        U5      nU* U/U l        g [	        U R
                  SU 3-   5      e)Nrm   rh  r   r   )r   r   rV   rj  r   _FACTOR_VALIDATION_ERROR_check_factor_rangerk  _factorintfloatr   )r$   r'  s     r   rb  RandomBrightness._set_factor  s    fudm,,6{a 11d6(OC  $$VAY/$$VAY/!&>DLe--$$V,[F#GV,DLT::tF8_LMMr   c                 R    US:  d  US:  a  [        U R                  SU 3-   5      eg )Nr   r<  rh  )r   ro  )r$   input_numbers     r   rp  $RandomBrightness._check_factor_range  s8    #!4--$|n0EE  "5r   c                 \    [        XR                  S9nU(       a  U R                  U5      $ U$ r   )r:   r7   _brightness_adjust)r$   r1   r   s      r   rF   RandomBrightness.call  s+    .@.@A**622Mr   c                    UR                   R                  nUS:X  a  SnO<US:X  a  [        R                   " U5      S   SSS/nO[        SUR                    35      eU R                  R                  UU R                  S   U R                  S   S9nX@R                  S   U R                  S   -
  -  n[        R                  " XAR                  5      nX-  n[        R                  " XR                  S   U R                  S   5      $ )Nr   )r   r   r      r   r   z?Expected the input image to be rank 3 or 4. Got inputs.shape = r,  )r<   r   r8   r   r   r   rq  rl  rA   r*   rW  )r$   r  r   rgb_delta_shape	rgb_deltas        r   ry  #RandomBrightness._brightness_adjust  s   ||  19'OQY  "xx/2Aq!<O""(,,1  **99!<<?<<? : 
	
 !2!21!58I8I!8L!LM	GGI||4	%%a($*;*;A*>
 	
r   c                    > U R                   U R                  U R                  S.n[        TU ]  5       n[        [        UR                  5       5      [        UR                  5       5      -   5      $ )N)r'  re  r   )rq  rl  rd  r"   rT   rU   rV   rW   rX   s      r   rT   RandomBrightness.get_config  sY    ll,,JJ

 g(*D**,-V\\^0DDEEr   )rq  rd  rl  ))r   rT  Nr   )r]   r^   r_   r`   ra   ro  ri  r#   rc  rb  rp  rF   ry  rT   rb   rc   rd   s   @r   r`  r`  3  sI    :z	% 
 	G "	0N 
2F Fr   r`  zkeras.layers.RandomHeightz4keras.layers.experimental.preprocessing.RandomHeightc                   L   ^  \ rS rSrSrSU 4S jjrS	S jrS rU 4S jrSr	U =r
$ )
RandomHeighti  a  A preprocessing layer which randomly varies image height during training.

This layer adjusts the height of a batch of images by a random factor.
The input should be a 3D (unbatched) or 4D (batched) tensor in the
`"channels_last"` image data format. 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.


By default, this layer is inactive during inference.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

Args:
    factor: A positive float (fraction of original height),
        or a tuple of size 2 representing lower and upper bound
        for resizing vertically. When represented as a single float,
        this value is used for both the upper and
        lower bound. For instance, `factor=(0.2, 0.3)` results
        in an output with
        height changed by a random amount in the range `[20%, 30%]`.
        `factor=(-0.2, 0.3)` results in an output with height
        changed by a random amount in the range `[-20%, +30%]`.
        `factor=0.2` results in an output with
        height changed by a random amount in the range `[-20%, +20%]`.
    interpolation: String, the interpolation method.
        Supports `"bilinear"`, `"nearest"`, `"bicubic"`, `"area"`,
        `"lanczos3"`, `"lanczos5"`, `"gaussian"`, `"mitchellcubic"`.
        Defaults to `"bilinear"`.
    seed: Integer. Used to create a random seed.

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

Output shape:
    3D (unbatched) or 4D (batched) tensor with shape:
    `(..., random_height, width, channels)`.
c                   > [         TU ]  " SUSS.UD6  Xl        [        U[        [
        45      (       a  US   U l        US   U l        OU* U l        Xl        U R                  U R                  :  a  [        SU 35      eU R                  S:  d  U R                  S:  a  [        SU 35      eX l	        [        R                  " U5      U l        X0l        g )	NTr   r   r   z[`factor` argument cannot have an upper bound lesser than the lower bound. Received: factor=r<  D`factor` argument must have values larger than -1. Received: factor=r   )r"   r#   r'  r   r   rV   r   r   r   r   r   r    r!   r   r$   r'  r   r   r%   r&   s        r   r#   RandomHeight.__init__  s    CdDCFCfudm,, &q	D &q	D!'D &t000117:  t#t'8'84'?$$*8-  +%0%B%B&
" 	r   c                 H   ^  [        U5      nU 4S jnU(       a  U" U5      $ U$ )Nc                   > [         R                  " U 5      n[         R                  " U[           [         R                  5      nU[
           nT	R                  R                  / ST	R                  -   ST	R                  -   S9n[         R                  " XB-  [         R                  5      n[         R                  " XS/5      n[         R                  R                  U UT	R                  S9n[         R                  " UT	R                  5      nU R                  R!                  5       nSU[        '   UR#                  U5        U$ )z'Inputs height-adjusted with random ops.r   r,  r  r,   r6   N)r8   r<   rA   rL   r9   rM   r   r   r   r   rn   stackr?   r@   r!   r7   rK   r   )
r1   r   r   r   r   adjusted_heightadjusted_sizer   r  r$   s
            r   random_height_inputs/RandomHeight.call.<locals>.random_height_inputs  s   88F+LWW\&12::>F!&)F 22AAd///d/// B M
 !ggm&<bhhGOHHo%>?MXX__"11 % F WWVT%7%78F!<<//1L#'L \*Mr   r:   )r$   r1   r   r  s   `   r   rF   RandomHeight.call  s'    '	0 '//Mr   c                     [         R                  " U5      R                  5       nS U[        '   [         R                  " U5      $ rI   )r8   r;   rK   rL   rN   s     r   rP   !RandomHeight.compute_output_shape3  2    nn[199;"F~~k**r   c                    > U R                   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   r   r"   rT   rU   rV   rW   rX   s      r   rT   RandomHeight.get_config8  Y    kk!//II

 g(*D**,-V\\^0DDEEr   )r!   r'  r   r   r   r   r   Nr   r\   rd   s   @r   r  r    s%    'R4@+
F Fr   r  zkeras.layers.RandomWidthz3keras.layers.experimental.preprocessing.RandomWidthc                   L   ^  \ rS rSrSrSU 4S jjrS	S jrS rU 4S jrSr	U =r
$ )
RandomWidthiB  a  A preprocessing layer which randomly varies image width during training.

This layer will randomly adjusts the width of a batch of images of a
batch of images by a random factor. The input should be a 3D (unbatched) or
4D (batched) tensor in the `"channels_last"` image data format. 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.

By default, this layer is inactive during inference.

For an overview and full list of preprocessing layers, see the preprocessing
[guide](https://www.tensorflow.org/guide/tf_keras/preprocessing_layers).

Args:
    factor: A positive float (fraction of original width),
        or a tuple of size 2 representing lower and upper bound
        for resizing horizontally. When represented as a single float,
        this value is used for both the upper and
        lower bound. For instance, `factor=(0.2, 0.3)`
        results in an output with
        width changed by a random amount in the range `[20%, 30%]`.
        `factor=(-0.2, 0.3)` results in an output with width changed
        by a random amount in the range `[-20%, +30%]`.
        `factor=0.2` results in an output with width changed
        by a random amount in the range `[-20%, +20%]`.
    interpolation: String, the interpolation method.
        Supports `"bilinear"`, `"nearest"`, `"bicubic"`, `"area"`,
        `"lanczos3"`, `"lanczos5"`, `"gaussian"`, `"mitchellcubic"`.
        Defaults to `bilinear`.
    seed: Integer. Used to create a random seed.

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

Output shape:
    3D (unbatched) or 4D (batched) tensor with shape:
    `(..., height, random_width, channels)`.
c                   > [         TU ]  " SUSS.UD6  Xl        [        U[        [
        45      (       a  US   U l        US   U l        OU* U l        Xl        U R                  U R                  :  a  [        SU 35      eU R                  S:  d  U R                  S:  a  [        SU 35      eX l	        [        R                  " U5      U l        X0l        g )	NTr   r   r   zY`factor` argument cannot have an upper bound less than the lower bound. Received: factor=r<  r  r   )r"   r#   r'  r   r   rV   r   r   r   r   r   r    r!   r   r  s        r   r#   RandomWidth.__init__p  s    CdDCFCfudm,,%ayD%ayD &wD%d...117:  d"d&6&6&=$$*8-  +%0%B%B&
" 	r   c                 H   ^  [        U5      nU 4S jnU(       a  U" U5      $ U$ )Nc                   > [         R                  " U 5      nU[           n[         R                  " U[           [         R
                  5      nT	R                  R                  / ST	R                  -   ST	R                  -   S9n[         R                  " XC-  [         R                  5      n[         R                  " X%/5      n[         R                  R                  U UT	R                  S9n[         R                  " UT	R                  5      nU R                  R!                  5       nSU[        '   UR#                  U5        U$ )z&Inputs width-adjusted with random ops.r   r,  r  N)r8   r<   rL   rA   rM   r9   r   r   r   r   rn   r  r?   r@   r!   r7   rK   r   )
r1   r   r   r   r   adjusted_widthr  r   r  r$   s
            r   random_width_inputs-RandomWidth.call.<locals>.random_width_inputs  s   88F+L!&)FWW\&12::>F11@@d...d... A L
  WW\%:BHHENHHf%=>MXX__"11 % F WWVT%7%78F!<<//1L#'L \*Mr   r  )r$   r1   r   r  s   `   r   rF   RandomWidth.call  s'    '	0 &v..Mr   c                     [         R                  " U5      R                  5       nS U[        '   [         R                  " U5      $ rI   )r8   r;   rK   rM   rN   s     r   rP    RandomWidth.compute_output_shape  r  r   c                    > U R                   U R                  U R                  S.n[        TU ]  5       n[        [        UR                  5       5      [        UR                  5       5      -   5      $ r  r  rX   s      r   rT   RandomWidth.get_config  r  r   )r!   r'  r   r   r   r   r  r   r\   rd   s   @r   r  r  B  s%    &P2@+
F Fr   r  c                     [        U [        5      (       a  [        S[        U 5       S35      e[        R
                  " XS9n U $ )NzhThis layer can only process a tensor representing an image or a batch of images. Received: type(inputs)=z.If you need to pass a dict containing images, labels, and bounding boxes, you should instead use the preprocessing and augmentation layers from `keras_cv.layers`. See docs at https://keras.io/api/keras_cv/layers/r)   )r   rU   r   typeutilsensure_tensor)r1   r*   s     r   r:   r:     sL    &$99=f G44
 	
   5FMr   rI   )r   r   r   NN),ra   numpyr.  tensorflow.compat.v2compatv2r8    tensorflow.python.util.tf_exportr   tf_keras.srcr   tf_keras.src.enginer   !tf_keras.src.layers.preprocessingr   r  tf_keras.src.utilsr   r   rL   rM   r   Layerr   rf   BaseRandomLayerr   r   r   r   r   r   r   r   r   r#  r%  r:  r@  rO  r`  r  r  r:   r   r   r   <module>r     s   (  ! ! 9   * J * '		

 ObFz bFbFJ 8HF!! HF	HFV 8	
UF++ UF
UFp 75F
   5F	5Fp 
3  8	
]F++ ]F
]FB $?	
pF
22 pF
pFf
J 	_
D1
h !<	
JFZ// JF
JFZ 8	
vF++ vF
vFr(
V !<	
YFZ// YF
YFx -"5SFz11 SF 6SFl :	
pF:-- pF
pFf 9	
nF*,, nF
nFbr   