



import random
import timeit
from functools import wraps
from typing import Callable, Optional

from ..configuration_utils import PretrainedConfig
from ..models.auto.modeling_tf_auto import TF_MODEL_MAPPING, TF_MODEL_WITH_LM_HEAD_MAPPING
from ..utils import is_pyanvml_available, is_tf_available, logging
from .benchmark_utils import (
    Benchmark,
    Memory,
    MemorySummary,
    measure_peak_memory_cpu,
    start_memory_tracing,
    stop_memory_tracing,
)


if is_tf_available():
      import tensorflow as tf
      from tensorflow.python.framework.errors_impl import ResourceExhaustedError

      from .benchmark_args_tf import TensorFlowBenchmarkArguments

if is_pyanvml_available():
      import pyanvml.pyanvml as nvml

_lowerCamelCase						    =  logging.get_logger(__name__)






def 	_lowerCAmelCase						(				__lowerCamelCase   :     Tuple		,	__lowerCamelCase   :     Any     ):



 """simple docstring"""





 def run_func(__lowerCamelCase   :     Optional[Any]     ):
  @wraps(__A     )
  def run_in_eager_mode(*__lowerCamelCase   :     List[Any]		,	**__lowerCamelCase   :     Tuple     ):
   return func(*__A		,	**__A     )

  @wraps(__A     )
  @tf.function(experimental_compile=__A     )
  def run_in_graph_mode(*__lowerCamelCase   :     Optional[int]		,	**__lowerCamelCase   :     List[str]     ):
   return func(*__A		,	**__A     )

  if do_eager_mode is True:
   if use_xla is not False:
    raise ValueError(
        "Cannot run model in XLA, if `args.eager_mode` is set to `True`. Please set `args.eager_mode=False`."     )
   return run_in_eager_mode
  else:
   return run_in_graph_mode

 return run_func






def 	_lowerCAmelCase						(				__lowerCamelCase   :     str		,	__lowerCamelCase   :     Dict		,	__lowerCamelCase   :     str     ):



 """simple docstring"""





 __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	random.Random()
 __SCREAMING_SNAKE_CASE       :    Any       =	[rng.randint(0		,	vocab_size - 1     ) for i in range(batch_size * sequence_length     )]
 return tf.constant(__A		,	shape=(batch_size, sequence_length)		,	dtype=tf.intaa     )






class       _SCREAMING_SNAKE_CASE	(__lowerCAmelCase ):
     lowerCAmelCase     :   str					=			42
     lowerCAmelCase     :   Optional[Any]					=			42
     lowerCAmelCase     :   Optional[int]					=			"""TensorFlow"""





     @property
     def 	__snake_case    (       self :							Any				)->List[str]:
      return tf.__version__





     def 	__snake_case    (       self :							List[Any]     ,  UpperCamelCase :							str     ,  UpperCamelCase :							int     ,  UpperCamelCase :							int				)->float:
      __SCREAMING_SNAKE_CASE       :    List[str]       =	self.args.strategy
      if strategy is None:
       raise ValueError("A device strategy has to be initialized before using TensorFlow."				)
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	self._prepare_inference_func(_UpperCamelCase     ,  _UpperCamelCase     ,  _UpperCamelCase				)
      return self._measure_speed(_inference				)





     def 	__snake_case    (       self :							Dict     ,  UpperCamelCase :							str     ,  UpperCamelCase :							int     ,  UpperCamelCase :							int				)->float:
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	self.args.strategy
      if strategy is None:
       raise ValueError("A device strategy has to be initialized before using TensorFlow."				)
      __SCREAMING_SNAKE_CASE       :    str       =	self._prepare_train_func(_UpperCamelCase     ,  _UpperCamelCase     ,  _UpperCamelCase				)
      return self._measure_speed(_train				)





     def 	__snake_case    (       self :							Tuple     ,  UpperCamelCase :							str     ,  UpperCamelCase :							int     ,  UpperCamelCase :							int				)->[Memory, Optional[MemorySummary]]:


      if self.args.is_gpu:
       tf.config.experimental.set_memory_growth(self.args.gpu_list[self.args.device_idx]     ,  _UpperCamelCase				)
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	self.args.strategy
      if strategy is None:
       raise ValueError("A device strategy has to be initialized before using TensorFlow."				)
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	self._prepare_inference_func(_UpperCamelCase     ,  _UpperCamelCase     ,  _UpperCamelCase				)
      return self._measure_memory(_inference				)





     def 	__snake_case    (       self :							Optional[int]     ,  UpperCamelCase :							str     ,  UpperCamelCase :							int     ,  UpperCamelCase :							int				)->[Memory, Optional[MemorySummary]]:


      if self.args.is_gpu:
       tf.config.experimental.set_memory_growth(self.args.gpu_list[self.args.device_idx]     ,  _UpperCamelCase				)
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	self.args.strategy
      if strategy is None:
       raise ValueError("A device strategy has to be initialized before using TensorFlow."				)

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	self._prepare_train_func(_UpperCamelCase     ,  _UpperCamelCase     ,  _UpperCamelCase				)
      return self._measure_memory(_train				)





     def 	__snake_case    (       self :							int     ,  UpperCamelCase :							str     ,  UpperCamelCase :							int     ,  UpperCamelCase :							int				)->Callable[[], None]:
      __SCREAMING_SNAKE_CASE       :    Tuple       =	self.config_dict[model_name]

      if self.args.fpaa:
       raise NotImplementedError("Mixed precision is currently not supported."				)

      __SCREAMING_SNAKE_CASE       :    Dict       =	(
          hasattr(_UpperCamelCase     ,  "architectures"				)
          and isinstance(config.architectures     ,  _UpperCamelCase				)
          and len(config.architectures				) > 0
      )
      if not self.args.only_pretrain_model and has_model_class_in_config:
       try:
        __SCREAMING_SNAKE_CASE       :    Dict       =	"""TF""" + config.architectures[0]  # prepend 'TF' for tensorflow model
        __SCREAMING_SNAKE_CASE       :    List[Any]       =	__import__("transformers"     ,  fromlist=[model_class]				)
        __SCREAMING_SNAKE_CASE       :    int       =	getattr(_UpperCamelCase     ,  _UpperCamelCase				)
        __SCREAMING_SNAKE_CASE       :    int       =	model_cls(_UpperCamelCase				)
       except ImportError:
        raise ImportError(
            F"""{model_class} does not exist. If you just want to test the pretrained model, you might want to"""
            " set `--only_pretrain_model` or `args.only_pretrain_model=True`."				)
      else:
       __SCREAMING_SNAKE_CASE       :    List[Any]       =	TF_MODEL_MAPPING[config.__class__](_UpperCamelCase				)

      # encoder-decoder has vocab size saved differently
      __SCREAMING_SNAKE_CASE       :    int       =	config.vocab_size if hasattr(_UpperCamelCase     ,  "vocab_size"				) else config.encoder.vocab_size
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	random_input_ids(_UpperCamelCase     ,  _UpperCamelCase     ,  _UpperCamelCase				)

      @run_with_tf_optimizations(self.args.eager_mode     ,  self.args.use_xla				)
      def encoder_decoder_forward():
       return model(_UpperCamelCase     ,  decoder_input_ids=_UpperCamelCase     ,  training=_UpperCamelCase				)

      @run_with_tf_optimizations(self.args.eager_mode     ,  self.args.use_xla				)
      def encoder_forward():
       return model(_UpperCamelCase     ,  training=_UpperCamelCase				)

      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	encoder_decoder_forward if config.is_encoder_decoder else encoder_forward

      return _inference





     def 	__snake_case    (       self :							Dict     ,  UpperCamelCase :							str     ,  UpperCamelCase :							int     ,  UpperCamelCase :							int				)->Callable[[], None]:
      __SCREAMING_SNAKE_CASE       :    Any       =	self.config_dict[model_name]

      if self.args.eager_mode is not False:
       raise ValueError("Training cannot be done in eager mode. Please make sure that `args.eager_mode = False`."				)

      if self.args.fpaa:
       raise NotImplementedError("Mixed precision is currently not supported."				)

      __SCREAMING_SNAKE_CASE       :    List[str]       =	(
          hasattr(_UpperCamelCase     ,  "architectures"				)
          and isinstance(config.architectures     ,  _UpperCamelCase				)
          and len(config.architectures				) > 0
      )
      if not self.args.only_pretrain_model and has_model_class_in_config:
       try:
        __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	"""TF""" + config.architectures[0]  # prepend 'TF' for tensorflow model
        __SCREAMING_SNAKE_CASE       :    str       =	__import__("transformers"     ,  fromlist=[model_class]				)
        __SCREAMING_SNAKE_CASE       :    int       =	getattr(_UpperCamelCase     ,  _UpperCamelCase				)
        __SCREAMING_SNAKE_CASE       :    Optional[int]       =	model_cls(_UpperCamelCase				)
       except ImportError:
        raise ImportError(
            F"""{model_class} does not exist. If you just want to test the pretrained model, you might want to"""
            " set `--only_pretrain_model` or `args.only_pretrain_model=True`."				)
      else:
       __SCREAMING_SNAKE_CASE       :    List[str]       =	TF_MODEL_WITH_LM_HEAD_MAPPING[config.__class__](_UpperCamelCase				)

      # encoder-decoder has vocab size saved differently
      __SCREAMING_SNAKE_CASE       :    int       =	config.vocab_size if hasattr(_UpperCamelCase     ,  "vocab_size"				) else config.encoder.vocab_size
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	random_input_ids(_UpperCamelCase     ,  _UpperCamelCase     ,  _UpperCamelCase				)

      @run_with_tf_optimizations(self.args.eager_mode     ,  self.args.use_xla				)
      def encoder_decoder_train():
       __SCREAMING_SNAKE_CASE       :    Dict       =	model(_UpperCamelCase     ,  decoder_input_ids=_UpperCamelCase     ,  labels=_UpperCamelCase     ,  training=_UpperCamelCase				)[0]
       __SCREAMING_SNAKE_CASE       :    int       =	tf.gradients(_UpperCamelCase     ,  model.trainable_variables				)
       return gradients

      @run_with_tf_optimizations(self.args.eager_mode     ,  self.args.use_xla				)
      def encoder_train():
       __SCREAMING_SNAKE_CASE       :    Dict       =	model(_UpperCamelCase     ,  labels=_UpperCamelCase     ,  training=_UpperCamelCase				)[0]
       __SCREAMING_SNAKE_CASE       :    Any       =	tf.gradients(_UpperCamelCase     ,  model.trainable_variables				)
       return gradients

      __SCREAMING_SNAKE_CASE       :    List[str]       =	encoder_decoder_train if config.is_encoder_decoder else encoder_train

      return _train





     def 	__snake_case    (       self :							List[Any]     ,  UpperCamelCase :							int				)->float:


      with self.args.strategy.scope():
       try:
        if self.args.is_tpu or self.args.use_xla:
         # run additional 10 times to stabilize compilation for tpu
         logger.info("Do inference on TPU. Running model 5 times to stabilize compilation"				)
         timeit.repeat(_UpperCamelCase     ,  repeat=1     ,  number=5				)

        # as written in https://docs.python.org/2/library/timeit.html#timeit.Timer.repeat, min should be taken rather than the average
        __SCREAMING_SNAKE_CASE       :    Tuple       =	timeit.repeat(
            _UpperCamelCase     ,  repeat=self.args.repeat     ,  number=1_0     ,  )

        return min(_UpperCamelCase				) / 1_0.0
       except ResourceExhaustedError as e:
        self.print_fn(F"""Doesn't fit on GPU. {e}"""				)






     def 	__snake_case    (       self :							List[str]     ,  UpperCamelCase :							Callable[[], None]				)->[Memory, MemorySummary]:
      logger.info(
          "Note that TensorFlow allocates more memory than "
          "it might need to speed up computation. "
          "The memory reported here corresponds to the memory "
          "reported by `nvidia-smi`, which can vary depending "
          "on total available memory on the GPU that is used."				)
      with self.args.strategy.scope():
       try:
        if self.args.trace_memory_line_by_line:
         if not self.args.eager_mode:
          raise ValueError(
              "`args.eager_mode` is set to `False`. Make sure to run model in eager mode to measure memory"
              " consumption line by line."				)
         __SCREAMING_SNAKE_CASE       :    List[str]       =	start_memory_tracing("transformers"				)

        if self.args.is_tpu:
         # tpu
         raise NotImplementedError(
             "Memory Benchmarking is currently not implemented for TPU. Please disable memory benchmarking"
             " with `args.memory=False`"				)
        elif self.args.is_gpu:
         # gpu
         if not is_pyanvml_available():
          logger.warning(
              "py3nvml not installed, we won't log GPU memory usage. "
              "Install py3nvml (pip install py3nvml) to log information about GPU."				)
          __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	"""N/A"""
         else:
          logger.info(
              "Measuring total GPU usage on GPU device. Make sure to not have additional processes"
              " running on the same GPU."				)
          # init nvml
          nvml.nvmlInit()
          func()
          __SCREAMING_SNAKE_CASE       :    Optional[int]       =	nvml.nvmlDeviceGetHandleByIndex(self.args.device_idx				)
          __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	nvml.nvmlDeviceGetMemoryInfo(_UpperCamelCase				)
          __SCREAMING_SNAKE_CASE       :    int       =	meminfo.used
          __SCREAMING_SNAKE_CASE       :    List[Any]       =	Memory(_UpperCamelCase				)
          # shutdown nvml
          nvml.nvmlShutdown()
        else:
         # cpu
         if self.args.trace_memory_line_by_line:
          logger.info(
              "When enabling line by line tracing, the max peak memory for CPU is inaccurate in"
              " TensorFlow."				)
          __SCREAMING_SNAKE_CASE       :    str       =	None
         else:
          __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	measure_peak_memory_cpu(_UpperCamelCase				)
          __SCREAMING_SNAKE_CASE       :    List[Any]       =	Memory(_UpperCamelCase				) if isinstance(_UpperCamelCase     ,  _UpperCamelCase				) else memory_bytes
        if self.args.trace_memory_line_by_line:
         __SCREAMING_SNAKE_CASE       :    Any       =	stop_memory_tracing(_UpperCamelCase				)
         if memory is None:
          __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	summary.total
        else:
         __SCREAMING_SNAKE_CASE       :    List[str]       =	None

        return memory, summary
       except ResourceExhaustedError as e:
        self.print_fn(F"""Doesn't fit on GPU. {e}"""				)
        return "N/A", None











import unittest
from typing import Dict, List, Optional, Union

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import BridgeTowerImageProcessor

class       _SCREAMING_SNAKE_CASE	(unittest.TestCase ):





     def __init__(       self :							Union[str, Any]     ,  UpperCamelCase :							List[Any]     ,  UpperCamelCase :							bool = True     ,  UpperCamelCase :							Dict[str, int] = None     ,  UpperCamelCase :							int = 3_2     ,  UpperCamelCase :							bool = True     ,  UpperCamelCase :							Union[int, float] = 1 / 2_5_5     ,  UpperCamelCase :							bool = True     ,  UpperCamelCase :							bool = True     ,  UpperCamelCase :							Optional[Union[float, List[float]]] = [0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]     ,  UpperCamelCase :							Optional[Union[float, List[float]]] = [0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]     ,  UpperCamelCase :							bool = True     ,  UpperCamelCase :							Dict=7     ,  UpperCamelCase :							Dict=3_0     ,  UpperCamelCase :							Tuple=4_0_0     ,  UpperCamelCase :							Union[str, Any]=3     ,  )->Optional[int]:
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	parent
      __SCREAMING_SNAKE_CASE       :    str       =	do_resize
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	size if size is not None else {"shortest_edge": 2_8_8}
      __SCREAMING_SNAKE_CASE       :    List[str]       =	size_divisor
      __SCREAMING_SNAKE_CASE       :    str       =	do_rescale
      __SCREAMING_SNAKE_CASE       :    int       =	rescale_factor
      __SCREAMING_SNAKE_CASE       :    Tuple       =	do_normalize
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	do_center_crop
      __SCREAMING_SNAKE_CASE       :    List[str]       =	image_mean
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	image_std
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	do_pad
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	batch_size
      __SCREAMING_SNAKE_CASE       :    str       =	num_channels
      __SCREAMING_SNAKE_CASE       :    List[str]       =	min_resolution
      __SCREAMING_SNAKE_CASE       :    Tuple       =	max_resolution





     def 	__snake_case    (       self :							Optional[Any]				)->List[str]:
      return {
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_normalize": self.do_normalize,
          "do_resize": self.do_resize,
          "size": self.size,
          "size_divisor": self.size_divisor,
      }






     def 	__snake_case    (       self :							Optional[Any]     ,  UpperCamelCase :							Optional[int]     ,  UpperCamelCase :							Dict=False				)->Optional[Any]:
      if not batched:
       __SCREAMING_SNAKE_CASE       :    Optional[int]       =	self.size["shortest_edge"]
       __SCREAMING_SNAKE_CASE       :    List[Any]       =	image_inputs[0]
       if isinstance(UpperCamelCase     ,  Image.Image				):
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[Any]       =	image.size
       else:
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	image.shape[1], image.shape[2]
       __SCREAMING_SNAKE_CASE       :    Tuple       =	size / min(UpperCamelCase     ,  UpperCamelCase				)
       if h < w:
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    int       =	size, scale * w
       else:
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[str]       =	scale * h, size

       __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	int((1_3_3_3 / 8_0_0) * size				)
       if max(UpperCamelCase     ,  UpperCamelCase				) > max_size:
        __SCREAMING_SNAKE_CASE       :    Any       =	max_size / max(UpperCamelCase     ,  UpperCamelCase				)
        __SCREAMING_SNAKE_CASE       :    List[Any]       =	newh * scale
        __SCREAMING_SNAKE_CASE       :    Optional[int]       =	neww * scale

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[Any]       =	int(newh + 0.5				), int(neww + 0.5				)
       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	(
           newh // self.size_divisor * self.size_divisor,
           neww // self.size_divisor * self.size_divisor,
       )

      else:
       __SCREAMING_SNAKE_CASE       :    Optional[int]       =	[]
       for image in image_inputs:
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	self.get_expected_values([image]				)
        expected_values.append((expected_height, expected_width)				)
       __SCREAMING_SNAKE_CASE       :    int       =	max(UpperCamelCase     ,  key=lambda UpperCamelCase				: item[0]				)[0]
       __SCREAMING_SNAKE_CASE       :    List[str]       =	max(UpperCamelCase     ,  key=lambda UpperCamelCase				: item[1]				)[1]

      return expected_height, expected_width






@require_torch
@require_vision
class       _SCREAMING_SNAKE_CASE	(UpperCamelCase			,    unittest.TestCase ):
     lowerCAmelCase					=			BridgeTowerImageProcessor if is_vision_available() else None





     def 	__snake_case    (       self :							str				)->int:
      __SCREAMING_SNAKE_CASE       :    str       =	BridgeTowerImageProcessingTester(self				)





     @property
     def 	__snake_case    (       self :							str				)->Any:
      return self.image_processor_tester.prepare_image_processor_dict()





     def 	__snake_case    (       self :							Optional[int]				)->Dict:
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	self.image_processing_class(**self.image_processor_dict				)
      self.assertTrue(hasattr(UpperCamelCase     ,  "image_mean"				)				)
      self.assertTrue(hasattr(UpperCamelCase     ,  "image_std"				)				)
      self.assertTrue(hasattr(UpperCamelCase     ,  "do_normalize"				)				)
      self.assertTrue(hasattr(UpperCamelCase     ,  "do_resize"				)				)
      self.assertTrue(hasattr(UpperCamelCase     ,  "size"				)				)
      self.assertTrue(hasattr(UpperCamelCase     ,  "size_divisor"				)				)





     def 	__snake_case    (       self :							Optional[int]				)->int:
      pass





     def 	__snake_case    (       self :							str				)->Union[str, Any]:
      # Initialize image processor
      __SCREAMING_SNAKE_CASE       :    Any       =	self.image_processing_class(**self.image_processor_dict				)
      # create random PIL images
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	prepare_image_inputs(self.image_processor_tester     ,  equal_resolution=UpperCamelCase				)
      for image in image_inputs:
       self.assertIsInstance(UpperCamelCase     ,  Image.Image				)

      # Test not batched input
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	image_processing(image_inputs[0]     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Tuple       =	self.image_processor_tester.get_expected_values(UpperCamelCase				)
      self.assertEqual(
          encoded_images.shape     ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,  )

      # Test batched
      __SCREAMING_SNAKE_CASE       :    Any       =	image_processing(UpperCamelCase     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	self.image_processor_tester.get_expected_values(UpperCamelCase     ,  batched=UpperCamelCase				)
      self.assertEqual(
          encoded_images.shape     ,  (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          )     ,  )





     def 	__snake_case    (       self :							List[str]				)->Optional[int]:
      # Initialize image processor
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	self.image_processing_class(**self.image_processor_dict				)
      # create random numpy tensors
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	prepare_image_inputs(self.image_processor_tester     ,  equal_resolution=UpperCamelCase     ,  numpify=UpperCamelCase				)
      for image in image_inputs:
       self.assertIsInstance(UpperCamelCase     ,  np.ndarray				)

      # Test not batched input
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	image_processing(image_inputs[0]     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[int]       =	self.image_processor_tester.get_expected_values(UpperCamelCase				)
      self.assertEqual(
          encoded_images.shape     ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,  )

      # Test batched
      __SCREAMING_SNAKE_CASE       :    str       =	image_processing(UpperCamelCase     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[Any]       =	self.image_processor_tester.get_expected_values(UpperCamelCase     ,  batched=UpperCamelCase				)
      self.assertEqual(
          encoded_images.shape     ,  (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          )     ,  )






     def 	__snake_case    (       self :							Optional[Any]				)->Union[str, Any]:
      # Initialize image processor
      __SCREAMING_SNAKE_CASE       :    Dict       =	self.image_processing_class(**self.image_processor_dict				)
      # create random PyTorch tensors
      __SCREAMING_SNAKE_CASE       :    List[str]       =	prepare_image_inputs(self.image_processor_tester     ,  equal_resolution=UpperCamelCase     ,  torchify=UpperCamelCase				)
      for image in image_inputs:
       self.assertIsInstance(UpperCamelCase     ,  torch.Tensor				)

      # Test not batched input
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	image_processing(image_inputs[0]     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Dict       =	self.image_processor_tester.get_expected_values(UpperCamelCase				)
      self.assertEqual(
          encoded_images.shape     ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,  )

      # Test batched
      __SCREAMING_SNAKE_CASE       :    str       =	image_processing(UpperCamelCase     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Any       =	self.image_processor_tester.get_expected_values(UpperCamelCase     ,  batched=UpperCamelCase				)
      self.assertEqual(
          encoded_images.shape     ,  (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          )     ,  )






