





'''simple docstring'''

import collections
import gzip
import os
import urllib

import numpy
from tensorflow.python.framework import dtypes, random_seed
from tensorflow.python.platform import gfile
from tensorflow.python.util.deprecation import deprecated

a        =						collections.namedtuple("_Datasets", ["train", "validation", "test"])

# CVDF mirror of http://yann.lecun.com/exdb/mnist/
a        =						"https://storage.googleapis.com/cvdf-datasets/mnist/"

def 						__magic_name__       (							__UpperCAmelCase      )						->					Tuple:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       numpy.dtype(numpy.uintaa      ).newbyteorder(""">"""      )
   return numpy.frombuffer(bytestream.read(4      )							,	dtype=__UpperCAmelCase      )[0]

@deprecated(__UpperCAmelCase							,	"""Please use tf.data to implement this functionality."""      )
def 						__magic_name__       (							__UpperCAmelCase      )						->					int:

   '''simple docstring'''







   print("""Extracting"""							,	f.name      )
   with gzip.GzipFile(fileobj=__UpperCAmelCase      ) as bytestream:
      __SCREAMING_SNAKE_CASE      							=       _readaa(__UpperCAmelCase      )
      if magic != 2051:
         raise ValueError(
             """Invalid magic number %d in MNIST image file: %s""" % (magic, f.name)      )
      __SCREAMING_SNAKE_CASE      							=       _readaa(__UpperCAmelCase      )
      __SCREAMING_SNAKE_CASE      							=       _readaa(__UpperCAmelCase      )
      __SCREAMING_SNAKE_CASE      							=       _readaa(__UpperCAmelCase      )
      __SCREAMING_SNAKE_CASE      							=       bytestream.read(rows * cols * num_images      )
      __SCREAMING_SNAKE_CASE      							=       numpy.frombuffer(__UpperCAmelCase							,	dtype=numpy.uinta      )
      __SCREAMING_SNAKE_CASE      							=       data.reshape(__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase							,	1      )
      return data

@deprecated(__UpperCAmelCase							,	"""Please use tf.one_hot on tensors."""      )
def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase      )						->					Any:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       labels_dense.shape[0]
   __SCREAMING_SNAKE_CASE      							=       numpy.arange(__UpperCAmelCase      ) * num_classes
   __SCREAMING_SNAKE_CASE      							=       numpy.zeros((num_labels, num_classes)      )
   __SCREAMING_SNAKE_CASE      							=       1
   return labels_one_hot

@deprecated(__UpperCAmelCase							,	"""Please use tf.data to implement this functionality."""      )
def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase=False							,	__UpperCAmelCase=10      )						->					Optional[Any]:

   '''simple docstring'''







   print("""Extracting"""							,	f.name      )
   with gzip.GzipFile(fileobj=__UpperCAmelCase      ) as bytestream:
      __SCREAMING_SNAKE_CASE      							=       _readaa(__UpperCAmelCase      )
      if magic != 2049:
         raise ValueError(
             """Invalid magic number %d in MNIST label file: %s""" % (magic, f.name)      )
      __SCREAMING_SNAKE_CASE      							=       _readaa(__UpperCAmelCase      )
      __SCREAMING_SNAKE_CASE      							=       bytestream.read(__UpperCAmelCase      )
      __SCREAMING_SNAKE_CASE      							=       numpy.frombuffer(__UpperCAmelCase							,	dtype=numpy.uinta      )
      if one_hot:
         return _dense_to_one_hot(__UpperCAmelCase							,	__UpperCAmelCase      )
      return labels







class __a :





   @deprecated(
       lowerCamelCase				,"""Please use alternatives such as official/mnist/_DataSet.py"""
       """ from tensorflow/models."""				,)
   def __init__(					self				:			int				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			int				,lowerCamelCase				:			Dict=False				,lowerCamelCase				:			Optional[int]=False				,lowerCamelCase				:			List[str]=dtypes.floataa				,lowerCamelCase				:			Tuple=True				,lowerCamelCase				:			List[Any]=None				,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       random_seed.get_seed(lowerCamelCase    )
      # If op level seed is not set, use whatever graph level seed is returned
      numpy.random.seed(seeda if seed is None else seeda    )
      __SCREAMING_SNAKE_CASE      							=       dtypes.as_dtype(lowerCamelCase    ).base_dtype
      if dtype not in (dtypes.uinta, dtypes.floataa):
         raise TypeError("""Invalid image dtype %r, expected uint8 or float32""" % dtype    )
      if fake_data:
         __SCREAMING_SNAKE_CASE      							=       1_0000
         __SCREAMING_SNAKE_CASE      							=       one_hot
      else:
         assert (
             images.shape[0] == labels.shape[0]
         ), f"""images.shape: {images.shape} labels.shape: {labels.shape}"""
         __SCREAMING_SNAKE_CASE      							=       images.shape[0]

         # Convert shape from [num examples, rows, columns, depth]
         # to [num examples, rows*columns] (assuming depth == 1)
         if reshape:
            assert images.shape[3] == 1
            __SCREAMING_SNAKE_CASE      							=       images.reshape(
                images.shape[0]				,images.shape[1] * images.shape[2]    )
         if dtype == dtypes.floataa:
            # Convert from [0, 255] -> [0.0, 1.0].
            __SCREAMING_SNAKE_CASE      							=       images.astype(numpy.floataa    )
            __SCREAMING_SNAKE_CASE      							=       numpy.multiply(lowerCamelCase				,1.0 / 255.0    )
      __SCREAMING_SNAKE_CASE      							=       images
      __SCREAMING_SNAKE_CASE      							=       labels
      __SCREAMING_SNAKE_CASE      							=       0
      __SCREAMING_SNAKE_CASE      							=       0





   @property
   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

      return self._images





   @property
   def      UpperCAmelCase__     (					self				:			Union[str, Any]    ):

      '''simple docstring'''

      return self._labels





   @property
   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

      return self._num_examples





   @property
   def      UpperCAmelCase__     (					self				:			List[Any]    ):

      '''simple docstring'''

      return self._epochs_completed





   def      UpperCAmelCase__     (					self				:			int				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			Any=False				,lowerCamelCase				:			Dict=True    ):

      '''simple docstring'''

      if fake_data:
         __SCREAMING_SNAKE_CASE      							=       [1] * 784
         __SCREAMING_SNAKE_CASE      							=       [1] + [0] * 9 if self.one_hot else 0
         return (
             [fake_image for _ in range(lowerCamelCase    )],
             [fake_label for _ in range(lowerCamelCase    )],
         )
      __SCREAMING_SNAKE_CASE      							=       self._index_in_epoch
      # Shuffle for the first epoch
      if self._epochs_completed == 0 and start == 0 and shuffle:
         __SCREAMING_SNAKE_CASE      							=       numpy.arange(self._num_examples    )
         numpy.random.shuffle(lowerCamelCase    )
         __SCREAMING_SNAKE_CASE      							=       self.images[perma]
         __SCREAMING_SNAKE_CASE      							=       self.labels[perma]
      # Go to the next epoch
      if start + batch_size > self._num_examples:
         # Finished epoch
         self._epochs_completed += 1
         # Get the rest examples in this epoch
         __SCREAMING_SNAKE_CASE      							=       self._num_examples - start
         __SCREAMING_SNAKE_CASE      							=       self._images[start : self._num_examples]
         __SCREAMING_SNAKE_CASE      							=       self._labels[start : self._num_examples]
         # Shuffle the data
         if shuffle:
            __SCREAMING_SNAKE_CASE      							=       numpy.arange(self._num_examples    )
            numpy.random.shuffle(lowerCamelCase    )
            __SCREAMING_SNAKE_CASE      							=       self.images[perm]
            __SCREAMING_SNAKE_CASE      							=       self.labels[perm]
         # Start next epoch
         __SCREAMING_SNAKE_CASE      							=       0
         __SCREAMING_SNAKE_CASE      							=       batch_size - rest_num_examples
         __SCREAMING_SNAKE_CASE      							=       self._index_in_epoch
         __SCREAMING_SNAKE_CASE      							=       self._images[start:end]
         __SCREAMING_SNAKE_CASE      							=       self._labels[start:end]
         return (
             numpy.concatenate((images_rest_part, images_new_part)				,axis=0    ),
             numpy.concatenate((labels_rest_part, labels_new_part)				,axis=0    ),
         )
      else:
         self._index_in_epoch += batch_size
         __SCREAMING_SNAKE_CASE      							=       self._index_in_epoch
         return self._images[start:end], self._labels[start:end]





@deprecated(__UpperCAmelCase							,	"""Please write your own downloading logic."""      )
def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					Union[str, Any]:

   '''simple docstring'''







   if not gfile.Exists(__UpperCAmelCase      ):
      gfile.MakeDirs(__UpperCAmelCase      )
   __SCREAMING_SNAKE_CASE      							=       os.path.join(__UpperCAmelCase							,	__UpperCAmelCase      )
   if not gfile.Exists(__UpperCAmelCase      ):
      urllib.request.urlretrieve(__UpperCAmelCase							,	__UpperCAmelCase      )  # noqa: S310
      with gfile.GFile(__UpperCAmelCase      ) as f:
         __SCREAMING_SNAKE_CASE      							=       f.size()
      print("""Successfully downloaded"""							,	__UpperCAmelCase							,	__UpperCAmelCase							,	"""bytes."""      )
   return filepath







@deprecated(
    __UpperCAmelCase							,	"""Please use alternatives such as:""" """ tensorflow_datasets.load('mnist')"""      )
def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase=False							,	__UpperCAmelCase=False							,	__UpperCAmelCase=dtypes.floataa							,	__UpperCAmelCase=True							,	__UpperCAmelCase=5000							,	__UpperCAmelCase=None							,	__UpperCAmelCase=DEFAULT_SOURCE_URL							,	)						->					int:

   '''simple docstring'''







   if fake_data:

      def fake():
         return _DataSet(
             []							,	[]							,	fake_data=__UpperCAmelCase							,	one_hot=__UpperCAmelCase							,	dtype=__UpperCAmelCase							,	seed=__UpperCAmelCase      )

      __SCREAMING_SNAKE_CASE      							=       fake()
      __SCREAMING_SNAKE_CASE      							=       fake()
      __SCREAMING_SNAKE_CASE      							=       fake()
      return _Datasets(train=__UpperCAmelCase							,	validation=__UpperCAmelCase							,	test=__UpperCAmelCase      )

   if not source_url:  # empty string check
      __SCREAMING_SNAKE_CASE      							=       DEFAULT_SOURCE_URL

   __SCREAMING_SNAKE_CASE      							=       """train-images-idx3-ubyte.gz"""
   __SCREAMING_SNAKE_CASE      							=       """train-labels-idx1-ubyte.gz"""
   __SCREAMING_SNAKE_CASE      							=       """t10k-images-idx3-ubyte.gz"""
   __SCREAMING_SNAKE_CASE      							=       """t10k-labels-idx1-ubyte.gz"""

   __SCREAMING_SNAKE_CASE      							=       _maybe_download(
       __UpperCAmelCase							,	__UpperCAmelCase							,	source_url + train_images_file      )
   with gfile.Open(__UpperCAmelCase							,	"""rb"""      ) as f:
      __SCREAMING_SNAKE_CASE      							=       _extract_images(__UpperCAmelCase      )

   __SCREAMING_SNAKE_CASE      							=       _maybe_download(
       __UpperCAmelCase							,	__UpperCAmelCase							,	source_url + train_labels_file      )
   with gfile.Open(__UpperCAmelCase							,	"""rb"""      ) as f:
      __SCREAMING_SNAKE_CASE      							=       _extract_labels(__UpperCAmelCase							,	one_hot=__UpperCAmelCase      )

   __SCREAMING_SNAKE_CASE      							=       _maybe_download(
       __UpperCAmelCase							,	__UpperCAmelCase							,	source_url + test_images_file      )
   with gfile.Open(__UpperCAmelCase							,	"""rb"""      ) as f:
      __SCREAMING_SNAKE_CASE      							=       _extract_images(__UpperCAmelCase      )

   __SCREAMING_SNAKE_CASE      							=       _maybe_download(
       __UpperCAmelCase							,	__UpperCAmelCase							,	source_url + test_labels_file      )
   with gfile.Open(__UpperCAmelCase							,	"""rb"""      ) as f:
      __SCREAMING_SNAKE_CASE      							=       _extract_labels(__UpperCAmelCase							,	one_hot=__UpperCAmelCase      )

   if not 0 <= validation_size <= len(__UpperCAmelCase      ):
      __SCREAMING_SNAKE_CASE      							=       (
          """Validation size should be between 0 and """
          f"""{len(__UpperCAmelCase      )}. Received: {validation_size}."""
      )
      raise ValueError(__UpperCAmelCase      )

   __SCREAMING_SNAKE_CASE      							=       train_images[:validation_size]
   __SCREAMING_SNAKE_CASE      							=       train_labels[:validation_size]
   __SCREAMING_SNAKE_CASE      							=       train_images[validation_size:]
   __SCREAMING_SNAKE_CASE      							=       train_labels[validation_size:]

   __SCREAMING_SNAKE_CASE      							=       {"""dtype""": dtype, """reshape""": reshape, """seed""": seed}

   __SCREAMING_SNAKE_CASE      							=       _DataSet(__UpperCAmelCase							,	__UpperCAmelCase							,	**__UpperCAmelCase      )
   __SCREAMING_SNAKE_CASE      							=       _DataSet(__UpperCAmelCase							,	__UpperCAmelCase							,	**__UpperCAmelCase      )
   __SCREAMING_SNAKE_CASE      							=       _DataSet(__UpperCAmelCase							,	__UpperCAmelCase							,	**__UpperCAmelCase      )

   return _Datasets(train=__UpperCAmelCase							,	validation=__UpperCAmelCase							,	test=__UpperCAmelCase      )












'''simple docstring'''

import unittest

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


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import ChineseCLIPImageProcessor







class __a (   unittest.TestCase			):





   def __init__(					self				:			List[Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			List[str]=7				,lowerCamelCase				:			List[str]=3				,lowerCamelCase				:			List[str]=18				,lowerCamelCase				:			Any=30				,lowerCamelCase				:			Optional[Any]=400				,lowerCamelCase				:			Optional[Any]=True				,lowerCamelCase				:			Optional[Any]=None				,lowerCamelCase				:			Optional[int]=True				,lowerCamelCase				:			int=None				,lowerCamelCase				:			str=True				,lowerCamelCase				:			Dict=[0.48_145_466, 0.4_578_275, 0.40_821_073]				,lowerCamelCase				:			List[str]=[0.26_862_954, 0.26_130_258, 0.27_577_711]				,lowerCamelCase				:			Tuple=True				,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       size if size is not None else {"""height""": 224, """width""": 224}
      __SCREAMING_SNAKE_CASE      							=       crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
      __SCREAMING_SNAKE_CASE      							=       parent
      __SCREAMING_SNAKE_CASE      							=       batch_size
      __SCREAMING_SNAKE_CASE      							=       num_channels
      __SCREAMING_SNAKE_CASE      							=       image_size
      __SCREAMING_SNAKE_CASE      							=       min_resolution
      __SCREAMING_SNAKE_CASE      							=       max_resolution
      __SCREAMING_SNAKE_CASE      							=       do_resize
      __SCREAMING_SNAKE_CASE      							=       size
      __SCREAMING_SNAKE_CASE      							=       do_center_crop
      __SCREAMING_SNAKE_CASE      							=       crop_size
      __SCREAMING_SNAKE_CASE      							=       do_normalize
      __SCREAMING_SNAKE_CASE      							=       image_mean
      __SCREAMING_SNAKE_CASE      							=       image_std
      __SCREAMING_SNAKE_CASE      							=       do_convert_rgb





   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_center_crop": self.do_center_crop,
          "crop_size": self.crop_size,
          "do_normalize": self.do_normalize,
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_convert_rgb": self.do_convert_rgb,
      }





   def      UpperCAmelCase__     (					self				:			int				,lowerCamelCase				:			Union[str, Any]=False				,lowerCamelCase				:			str=False				,lowerCamelCase				:			str=False    ):

      '''simple docstring'''

      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

      if equal_resolution:
         __SCREAMING_SNAKE_CASE      							=       []
         for i in range(self.batch_size    ):
            image_inputs.append(
                np.random.randint(
                    255				,size=(self.num_channels, self.max_resolution, self.max_resolution)				,dtype=np.uinta    )    )
      else:
         __SCREAMING_SNAKE_CASE      							=       []
         for i in range(self.batch_size    ):
            __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       np.random.choice(np.arange(self.min_resolution				,self.max_resolution    )				,2    )
            image_inputs.append(np.random.randint(255				,size=(self.num_channels, width, height)				,dtype=np.uinta    )    )

      if not numpify and not torchify:
         # PIL expects the channel dimension as last dimension
         __SCREAMING_SNAKE_CASE      							=       [Image.fromarray(np.moveaxis(lowerCamelCase				,0				,-1    )    ) for x in image_inputs]

      if torchify:
         __SCREAMING_SNAKE_CASE      							=       [torch.from_numpy(lowerCamelCase    ) for x in image_inputs]

      return image_inputs







@require_torch
@require_vision
class __a (   _snake_case,   unittest.TestCase			):
   __UpperCamelCase   : int	      =	ChineseCLIPImageProcessor if is_vision_available() else None





   def      UpperCAmelCase__     (					self				:			Any    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ChineseCLIPImageProcessingTester(self				,do_center_crop=lowerCamelCase    )





   @property
   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_resize"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""size"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_center_crop"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""center_crop"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_normalize"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""image_mean"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""image_std"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_convert_rgb"""    )    )





   def      UpperCAmelCase__     (					self				:			List[Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class.from_dict(self.image_processor_dict    )
      self.assertEqual(image_processor.size				,{"""height""": 224, """width""": 224}    )
      self.assertEqual(image_processor.crop_size				,{"""height""": 18, """width""": 18}    )

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class.from_dict(self.image_processor_dict				,size=42				,crop_size=84    )
      self.assertEqual(image_processor.size				,{"""shortest_edge""": 42}    )
      self.assertEqual(image_processor.crop_size				,{"""height""": 84, """width""": 84}    )





   def      UpperCAmelCase__     (					self				:			Dict    ):

      '''simple docstring'''

      pass





   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PIL images
      __SCREAMING_SNAKE_CASE      							=       self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase    )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase				,Image.Image    )

      # Test not batched input
      __SCREAMING_SNAKE_CASE      							=       image_processing(image_inputs[0]				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)

      # Test batched
      __SCREAMING_SNAKE_CASE      							=       image_processing(lowerCamelCase				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)





   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random numpy tensors
      __SCREAMING_SNAKE_CASE      							=       self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase				,numpify=lowerCamelCase    )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase				,np.ndarray    )

      # Test not batched input
      __SCREAMING_SNAKE_CASE      							=       image_processing(image_inputs[0]				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)

      # Test batched
      __SCREAMING_SNAKE_CASE      							=       image_processing(lowerCamelCase				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)





   def      UpperCAmelCase__     (					self				:			str    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PyTorch tensors
      __SCREAMING_SNAKE_CASE      							=       self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase				,torchify=lowerCamelCase    )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase				,torch.Tensor    )

      # Test not batched input
      __SCREAMING_SNAKE_CASE      							=       image_processing(image_inputs[0]				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)

      # Test batched
      __SCREAMING_SNAKE_CASE      							=       image_processing(lowerCamelCase				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)







@require_torch
@require_vision
class __a (   _snake_case,   unittest.TestCase			):
   __UpperCamelCase   : Optional[int]	      =	ChineseCLIPImageProcessor if is_vision_available() else None





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ChineseCLIPImageProcessingTester(self				,num_channels=4				,do_center_crop=lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       3





   @property
   def      UpperCAmelCase__     (					self				:			Dict    ):

      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()





   def      UpperCAmelCase__     (					self				:			int    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_resize"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""size"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_center_crop"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""center_crop"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_normalize"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""image_mean"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""image_std"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_convert_rgb"""    )    )





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      pass





   def      UpperCAmelCase__     (					self				:			Union[str, Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PIL images
      __SCREAMING_SNAKE_CASE      							=       self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase    )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase				,Image.Image    )

      # Test not batched input
      __SCREAMING_SNAKE_CASE      							=       image_processing(image_inputs[0]				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              1,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)

      # Test batched
      __SCREAMING_SNAKE_CASE      							=       image_processing(lowerCamelCase				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              self.image_processor_tester.batch_size,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)





