o
    ?e-                     @   s   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dejeddddZedg dejdddZdS )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                 C      t |d| |gT}t j| dd} t j|tjdd}t| }tjt	
||kd||gdd}t|g|}|| d	 }tjt||j|jj|d
| }tj| |||dW  d   S 1 s`w   Y  dS )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   Z	summarize   r   maxvalseedN)r   
name_scopeconvert_to_tensorr   int32r   shaper   Assertr   
reduce_allr   with_dependenciesr   Zrandom_uniformr   maxslicer   r   r   r   r    checklimitoffset r*   f/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/ops/random_crop_ops.pyr      s*   %
$zimage.stateless_random_cropc                 C   r   )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	   Zstateless_random_uniformr   r$   r%   r&   r*   r*   r+   stateless_random_cropU   s*   #
$r,   )NN)N)__doc__Ztensorflow.python.frameworkr   r   Ztensorflow.python.opsr   r   r   r   r   r	   Ztensorflow.python.utilr
   r   Z tensorflow.python.util.tf_exportr   Zadd_dispatch_supportZdeprecated_endpointsr   r,   r*   r*   r*   r+   <module>   s&   
4