
    AVh-                     :   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZ  edddg      ej                    ej"                  d      dd                     Z edg       ej                   dd              Zy)z&Operations for random tensor cropping.    )dtypes)ops)	array_ops)control_flow_assert)control_flow_ops)math_ops)
random_ops)stateless_random_ops)deprecation)dispatch)	tf_exportzimage.random_croprandom_crop)v1Nc                 p   t        j                  |d| |g      5 }t        j                  | d      } t        j                  |t        j                  d      }t        j                  |       }t        j                  t        j                  ||k\        d||gd      }t        j                  |g|      }||z
  d	z   }t        j                  t        j                  |      |j                  |j                  j                   |
      |z  }t        j"                  | |||      cddd       S # 1 sw Y   yxY w)a  Randomly crops a tensor to a given size.

  Slices a shape `size` portion out of `value` at a uniformly chosen offset.
  Requires `value.shape >= size`.

  If a dimension should not be cropped, pass the full size of that dimension.
  For example, RGB images can be cropped with
  `size = [crop_height, crop_width, 3]`.

  Example usage:

  >>> image = [[1, 2, 3], [4, 5, 6]]
  >>> result = tf.image.random_crop(value=image, size=(1, 3))
  >>> result.shape.as_list()
  [1, 3]

  For producing deterministic results given a `seed` value, use
  `tf.image.stateless_random_crop`. Unlike using the `seed` param with
  `tf.image.random_*` ops, `tf.image.stateless_random_*` ops guarantee the same
  results given the same seed independent of how many times the function is
  called, and independent of global seed settings (e.g. tf.random.set_seed).

  Args:
    value: Input tensor to crop.
    size: 1-D tensor with size the rank of `value`.
    seed: Python integer. Used to create a random seed. See
      `tf.random.set_seed`
      for behavior.
    name: A name for this operation (optional).

  Returns:
    A cropped tensor of the same rank as `value` and shape `size`.
  r   valuenamesizedtyper   Need value.shape >= size, got   	summarize   r   maxvalseedN)r   
name_scopeconvert_to_tensorr   int32r   shaper   Assertr   
reduce_allr   with_dependenciesr	   random_uniformr   maxslicer   r   r   r   r"   checklimitoffsets           U/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/random_crop_ops.pyr   r      s
   J ~~dME4=9 ;T!!%g6E  V\\GDOOE"E&&ETM*	)5$7E ..w>EDL1E&&jjzz~~	 	F
 ??5&$T:; ; ;   DD,,D5zimage.stateless_random_cropc                 p   t        j                  |d| |g      5 }t        j                  | d      } t        j                  |t        j                  d      }t        j                  |       }t        j                  t        j                  ||k\        d||gd      }t        j                  |g|      }||z
  d	z   }t        j                  t        j                  |      |j                  |j                  j                   |
      |z  }t        j"                  | |||      cddd       S # 1 sw Y   yxY w)a  Randomly crops a tensor to a given size in a deterministic manner.

  Slices a shape `size` portion out of `value` at a uniformly chosen offset.
  Requires `value.shape >= size`.

  If a dimension should not be cropped, pass the full size of that dimension.
  For example, RGB images can be cropped with
  `size = [crop_height, crop_width, 3]`.

  Guarantees the same results given the same `seed` independent of how many
  times the function is called, and independent of global seed settings (e.g.
  `tf.random.set_seed`).

  Usage Example:

  >>> image = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]
  >>> seed = (1, 2)
  >>> tf.image.stateless_random_crop(value=image, size=(1, 2, 3), seed=seed)
  <tf.Tensor: shape=(1, 2, 3), dtype=int32, numpy=
  array([[[1, 2, 3],
          [4, 5, 6]]], dtype=int32)>

  Args:
    value: Input tensor to crop.
    size: 1-D tensor with size the rank of `value`.
    seed: A shape [2] Tensor, the seed to the random number generator. Must have
      dtype `int32` or `int64`. (When using XLA, only `int32` is allowed.)
    name: A name for this operation (optional).

  Returns:
    A cropped tensor of the same rank as `value` and shape `size`.
  r   r   r   r   r   r   r   r   r   r   N)r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r
   stateless_random_uniformr   r'   r(   r)   s           r-   stateless_random_cropr1   U   s
   F ~~dME4=9 ;T!!%g6E  V\\GDOOE"E&&ETM*	)5$7E ..w>EDL1E!::jjzz~~	 	F
 ??5&$T:; ; ;r.   )NN)N)__doc__tensorflow.python.frameworkr   r   tensorflow.python.opsr   r   r   r   r	   r
   tensorflow.python.utilr   r    tensorflow.python.util.tf_exportr   add_dispatch_supportdeprecated_endpointsr   r1        r-   <module>r;      s    - . + + 5 2 * , 6 . + 6 $7#GH	!!!-01; 1  I1;h (R0	0;  10;r:   