






"""simple docstring"""







import json
import os
import sys
import tempfile
import unittest
from pathlib import Path
from shutil import copyfile

from huggingface_hub import HfFolder, Repository, create_repo, delete_repo
from requests.exceptions import HTTPError

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    PROCESSOR_MAPPING,
    TOKENIZER_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    AutoProcessor,
    AutoTokenizer,
    BertTokenizer,
    ProcessorMixin,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
    WavaVecaProcessor,
)
from transformers.testing_utils import TOKEN, USER, get_tests_dir, is_staging_test
from transformers.tokenization_utils import TOKENIZER_CONFIG_FILE
from transformers.utils import FEATURE_EXTRACTOR_NAME, is_tokenizers_available


sys.path.append(str(Path(__file__).parent.parent.parent.parent / '''utils'''))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402
from test_module.custom_processing import CustomProcessor  # noqa E402
from test_module.custom_tokenization import CustomTokenizer  # noqa E402


lowerCAmelCase_	:    List[Any]            =      get_tests_dir('''fixtures/dummy_feature_extractor_config.json''')
lowerCAmelCase_	:    str            =      get_tests_dir('''fixtures/vocab.json''')
lowerCAmelCase_	:    int            =      get_tests_dir('''fixtures''')





class   UpperCamelCase_      (       unittest.TestCase  ):
  _A       :					Optional[Any]				=	["""[UNK]""", """[CLS]""", """[SEP]""", """[PAD]""", """[MASK]""", """bla""", """blou"""]



  def 		UpperCamelCase_				(      self				)			->			int:



         """simple docstring"""





         UpperCAmelCase	    =			0



  def 		UpperCamelCase_				(      self				)			->			List[str]:



         """simple docstring"""





         UpperCAmelCase	    =			AutoProcessor.from_pretrained("""facebook/wav2vec2-base-960h"""				)
         self.assertIsInstance(snake_case_ ,		snake_case_				)



  def 		UpperCamelCase_				(      self				)			->			Optional[int]:



         """simple docstring"""





         with tempfile.TemporaryDirectory() as tmpdirname:
                UpperCAmelCase	    =			WavaVecaConfig()
                UpperCAmelCase	    =			AutoProcessor.from_pretrained("""facebook/wav2vec2-base-960h"""				)

                # save in new folder
                model_config.save_pretrained(snake_case_				)
                processor.save_pretrained(snake_case_				)

                UpperCAmelCase	    =			AutoProcessor.from_pretrained(snake_case_				)

         self.assertIsInstance(snake_case_ ,		snake_case_				)



  def 		UpperCamelCase_				(      self				)			->			List[Any]:



         """simple docstring"""





         with tempfile.TemporaryDirectory() as tmpdirname:
                # copy relevant files
                copyfile(snake_case_ ,		os.path.join(snake_case_ ,		snake_case_				)				)
                copyfile(snake_case_ ,		os.path.join(snake_case_ ,		"""vocab.json"""				)				)

                UpperCAmelCase	    =			AutoProcessor.from_pretrained(snake_case_				)

         self.assertIsInstance(snake_case_ ,		snake_case_				)



  def 		UpperCamelCase_				(      self				)			->			Optional[Any]:



         """simple docstring"""





         with tempfile.TemporaryDirectory() as tmpdirname:
                UpperCAmelCase	    =			WavaVecaFeatureExtractor()
                UpperCAmelCase	    =			AutoTokenizer.from_pretrained("""facebook/wav2vec2-base-960h"""				)

                UpperCAmelCase	    =			WavaVecaProcessor(snake_case_ ,		snake_case_				)

                # save in new folder
                processor.save_pretrained(snake_case_				)

                # drop `processor_class` in tokenizer
                with open(os.path.join(snake_case_ ,		snake_case_				) ,		"""r"""				) as f:
                       UpperCAmelCase	    =			json.load(snake_case_				)
                       config_dict.pop("""processor_class"""				)

                with open(os.path.join(snake_case_ ,		snake_case_				) ,		"""w"""				) as f:
                       f.write(json.dumps(snake_case_				)				)

                UpperCAmelCase	    =			AutoProcessor.from_pretrained(snake_case_				)

         self.assertIsInstance(snake_case_ ,		snake_case_				)



  def 		UpperCamelCase_				(      self				)			->			Tuple:



         """simple docstring"""





         with tempfile.TemporaryDirectory() as tmpdirname:
                UpperCAmelCase	    =			WavaVecaFeatureExtractor()
                UpperCAmelCase	    =			AutoTokenizer.from_pretrained("""facebook/wav2vec2-base-960h"""				)

                UpperCAmelCase	    =			WavaVecaProcessor(snake_case_ ,		snake_case_				)

                # save in new folder
                processor.save_pretrained(snake_case_				)

                # drop `processor_class` in feature extractor
                with open(os.path.join(snake_case_ ,		snake_case_				) ,		"""r"""				) as f:
                       UpperCAmelCase	    =			json.load(snake_case_				)
                       config_dict.pop("""processor_class"""				)

                with open(os.path.join(snake_case_ ,		snake_case_				) ,		"""w"""				) as f:
                       f.write(json.dumps(snake_case_				)				)

                UpperCAmelCase	    =			AutoProcessor.from_pretrained(snake_case_				)

         self.assertIsInstance(snake_case_ ,		snake_case_				)



  def 		UpperCamelCase_				(      self				)			->			Any:



         """simple docstring"""





         with tempfile.TemporaryDirectory() as tmpdirname:
                UpperCAmelCase	    =			WavaVecaConfig(processor_class="""Wav2Vec2Processor"""				)
                model_config.save_pretrained(snake_case_				)
                # copy relevant files
                copyfile(snake_case_ ,		os.path.join(snake_case_ ,		"""vocab.json"""				)				)
                # create emtpy sample processor
                with open(os.path.join(snake_case_ ,		snake_case_				) ,		"""w"""				) as f:
                       f.write("""{}"""				)

                UpperCAmelCase	    =			AutoProcessor.from_pretrained(snake_case_				)

         self.assertIsInstance(snake_case_ ,		snake_case_				)



  def 		UpperCamelCase_				(      self				)			->			str:



         """simple docstring"""





         with self.assertRaises(snake_case_				):
                UpperCAmelCase	    =			AutoProcessor.from_pretrained("""hf-internal-testing/test_dynamic_processor"""				)
         # If remote code is disabled, we can't load this config.
         with self.assertRaises(snake_case_				):
                UpperCAmelCase	    =			AutoProcessor.from_pretrained(
                    """hf-internal-testing/test_dynamic_processor""" ,		trust_remote_code=snake_case_				)

         UpperCAmelCase	    =			AutoProcessor.from_pretrained("""hf-internal-testing/test_dynamic_processor""" ,		trust_remote_code=snake_case_				)
         self.assertTrue(processor.special_attribute_present				)
         self.assertEqual(processor.__class__.__name__ ,		"""NewProcessor"""				)

         UpperCAmelCase	    =			processor.feature_extractor
         self.assertTrue(feature_extractor.special_attribute_present				)
         self.assertEqual(feature_extractor.__class__.__name__ ,		"""NewFeatureExtractor"""				)

         UpperCAmelCase	    =			processor.tokenizer
         self.assertTrue(tokenizer.special_attribute_present				)
         if is_tokenizers_available():
                self.assertEqual(tokenizer.__class__.__name__ ,		"""NewTokenizerFast"""				)

                # Test we can also load the slow version
                UpperCAmelCase	    =			AutoProcessor.from_pretrained(
                    """hf-internal-testing/test_dynamic_processor""" ,		trust_remote_code=snake_case_ ,		use_fast=snake_case_				)
                UpperCAmelCase	    =			new_processor.tokenizer
                self.assertTrue(new_tokenizer.special_attribute_present				)
                self.assertEqual(new_tokenizer.__class__.__name__ ,		"""NewTokenizer"""				)
         else:
                self.assertEqual(tokenizer.__class__.__name__ ,		"""NewTokenizer"""				)



  def 		UpperCamelCase_				(      self				)			->			Optional[Any]:



         """simple docstring"""





         try:
                AutoConfig.register("""custom""" ,		snake_case_				)
                AutoFeatureExtractor.register(snake_case_ ,		snake_case_				)
                AutoTokenizer.register(snake_case_ ,		slow_tokenizer_class=snake_case_				)
                AutoProcessor.register(snake_case_ ,		snake_case_				)
                # Trying to register something existing in the Transformers library will raise an error
                with self.assertRaises(snake_case_				):
                       AutoProcessor.register(snake_case_ ,		snake_case_				)

                # Now that the config is registered, it can be used as any other config with the auto-API
                UpperCAmelCase	    =			CustomFeatureExtractor.from_pretrained(snake_case_				)

                with tempfile.TemporaryDirectory() as tmp_dir:
                       UpperCAmelCase	    =			os.path.join(snake_case_ ,		"""vocab.txt"""				)
                       with open(snake_case_ ,		"""w""" ,		encoding="""utf-8"""				) as vocab_writer:
                              vocab_writer.write("""""".join([x + """\n""" for x in self.vocab_tokens]				)				)
                       UpperCAmelCase	    =			CustomTokenizer(snake_case_				)

                UpperCAmelCase	    =			CustomProcessor(snake_case_ ,		snake_case_				)

                with tempfile.TemporaryDirectory() as tmp_dir:
                       processor.save_pretrained(snake_case_				)
                       UpperCAmelCase	    =			AutoProcessor.from_pretrained(snake_case_				)
                       self.assertIsInstance(snake_case_ ,		snake_case_				)

         finally:
                if "custom" in CONFIG_MAPPING._extra_content:
                       del CONFIG_MAPPING._extra_content["custom"]
                if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                       del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]
                if CustomConfig in TOKENIZER_MAPPING._extra_content:
                       del TOKENIZER_MAPPING._extra_content[CustomConfig]
                if CustomConfig in PROCESSOR_MAPPING._extra_content:
                       del PROCESSOR_MAPPING._extra_content[CustomConfig]



  def 		UpperCamelCase_				(      self				)			->			int:



         """simple docstring"""





         class   UpperCamelCase_      (       _snake_case  ):
           _A       :					Dict				=	False





         class   UpperCamelCase_      (       _snake_case  ):
           _A       :					Tuple				=	False





         class   UpperCamelCase_      (       _snake_case  ):
           _A       :					Dict				=	"""AutoFeatureExtractor"""
           _A       :					Any				=	"""AutoTokenizer"""
           _A       :					Union[str, Any]				=	False

         try:
                AutoConfig.register("""custom""" ,		snake_case_				)
                AutoFeatureExtractor.register(snake_case_ ,		snake_case_				)
                AutoTokenizer.register(snake_case_ ,		slow_tokenizer_class=snake_case_				)
                AutoProcessor.register(snake_case_ ,		snake_case_				)
                # If remote code is not set, the default is to use local classes.
                UpperCAmelCase	    =			AutoProcessor.from_pretrained("""hf-internal-testing/test_dynamic_processor"""				)
                self.assertEqual(processor.__class__.__name__ ,		"""NewProcessor"""				)
                self.assertFalse(processor.special_attribute_present				)
                self.assertFalse(processor.feature_extractor.special_attribute_present				)
                self.assertFalse(processor.tokenizer.special_attribute_present				)

                # If remote code is disabled, we load the local ones.
                UpperCAmelCase	    =			AutoProcessor.from_pretrained(
                    """hf-internal-testing/test_dynamic_processor""" ,		trust_remote_code=snake_case_				)
                self.assertEqual(processor.__class__.__name__ ,		"""NewProcessor"""				)
                self.assertFalse(processor.special_attribute_present				)
                self.assertFalse(processor.feature_extractor.special_attribute_present				)
                self.assertFalse(processor.tokenizer.special_attribute_present				)

                # If remote is enabled, we load from the Hub.
                UpperCAmelCase	    =			AutoProcessor.from_pretrained(
                    """hf-internal-testing/test_dynamic_processor""" ,		trust_remote_code=snake_case_				)
                self.assertEqual(processor.__class__.__name__ ,		"""NewProcessor"""				)
                self.assertTrue(processor.special_attribute_present				)
                self.assertTrue(processor.feature_extractor.special_attribute_present				)
                self.assertTrue(processor.tokenizer.special_attribute_present				)

         finally:
                if "custom" in CONFIG_MAPPING._extra_content:
                       del CONFIG_MAPPING._extra_content["custom"]
                if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                       del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]
                if CustomConfig in TOKENIZER_MAPPING._extra_content:
                       del TOKENIZER_MAPPING._extra_content[CustomConfig]
                if CustomConfig in PROCESSOR_MAPPING._extra_content:
                       del PROCESSOR_MAPPING._extra_content[CustomConfig]



  def 		UpperCamelCase_				(      self				)			->			List[str]:



         """simple docstring"""





         UpperCAmelCase	    =			AutoProcessor.from_pretrained("""hf-internal-testing/tiny-random-bert"""				)
         self.assertEqual(processor.__class__.__name__ ,		"""BertTokenizerFast"""				)



  def 		UpperCamelCase_				(      self				)			->			Optional[Any]:



         """simple docstring"""





         UpperCAmelCase	    =			AutoProcessor.from_pretrained("""hf-internal-testing/tiny-random-convnext"""				)
         self.assertEqual(processor.__class__.__name__ ,		"""ConvNextImageProcessor"""				)





@is_staging_test
class   UpperCamelCase_      (       unittest.TestCase  ):
  _A       :					int				=	["""[UNK]""", """[CLS]""", """[SEP]""", """[PAD]""", """[MASK]""", """bla""", """blou"""]



  @classmethod
  def 		UpperCamelCase_				(      cls				)			->			Tuple:



         """simple docstring"""





         UpperCAmelCase	    =			TOKEN
         HfFolder.save_token(snake_case_				)



  @classmethod
  def 		UpperCamelCase_				(      cls				)			->			List[str]:



         """simple docstring"""





         try:
                delete_repo(token=cls._token ,		repo_id="""test-processor"""				)
         except HTTPError:
                pass

         try:
                delete_repo(token=cls._token ,		repo_id="""valid_org/test-processor-org"""				)
         except HTTPError:
                pass

         try:
                delete_repo(token=cls._token ,		repo_id="""test-dynamic-processor"""				)
         except HTTPError:
                pass



  def 		UpperCamelCase_				(      self				)			->			int:



         """simple docstring"""





         UpperCAmelCase	    =			WavaVecaProcessor.from_pretrained(snake_case_				)
         with tempfile.TemporaryDirectory() as tmp_dir:
                processor.save_pretrained(
                    os.path.join(snake_case_ ,		"""test-processor"""				) ,		push_to_hub=snake_case_ ,		use_auth_token=self._token				)

                UpperCAmelCase	    =			WavaVecaProcessor.from_pretrained(f'''{USER}/test-processor'''				)
                for k, v in processor.feature_extractor.__dict__.items():
                       self.assertEqual(snake_case_ ,		getattr(new_processor.feature_extractor ,		snake_case_				)				)
                self.assertDictEqual(new_processor.tokenizer.get_vocab() ,		processor.tokenizer.get_vocab()				)



  def 		UpperCamelCase_				(      self				)			->			int:



         """simple docstring"""





         UpperCAmelCase	    =			WavaVecaProcessor.from_pretrained(snake_case_				)

         with tempfile.TemporaryDirectory() as tmp_dir:
                processor.save_pretrained(
                    os.path.join(snake_case_ ,		"""test-processor-org"""				) ,		push_to_hub=snake_case_ ,		use_auth_token=self._token ,		organization="""valid_org""" ,		)

                UpperCAmelCase	    =			WavaVecaProcessor.from_pretrained("""valid_org/test-processor-org"""				)
                for k, v in processor.feature_extractor.__dict__.items():
                       self.assertEqual(snake_case_ ,		getattr(new_processor.feature_extractor ,		snake_case_				)				)
                self.assertDictEqual(new_processor.tokenizer.get_vocab() ,		processor.tokenizer.get_vocab()				)



  def 		UpperCamelCase_				(      self				)			->			str:



         """simple docstring"""





         CustomFeatureExtractor.register_for_auto_class()
         CustomTokenizer.register_for_auto_class()
         CustomProcessor.register_for_auto_class()

         UpperCAmelCase	    =			CustomFeatureExtractor.from_pretrained(snake_case_				)

         with tempfile.TemporaryDirectory() as tmp_dir:
                UpperCAmelCase	    =			os.path.join(snake_case_ ,		"""vocab.txt"""				)
                with open(snake_case_ ,		"""w""" ,		encoding="""utf-8"""				) as vocab_writer:
                       vocab_writer.write("""""".join([x + """\n""" for x in self.vocab_tokens]				)				)
                UpperCAmelCase	    =			CustomTokenizer(snake_case_				)

         UpperCAmelCase	    =			CustomProcessor(snake_case_ ,		snake_case_				)

         with tempfile.TemporaryDirectory() as tmp_dir:
                create_repo(f'''{USER}/test-dynamic-processor''' ,		token=self._token				)
                UpperCAmelCase	    =			Repository(snake_case_ ,		clone_from=f'''{USER}/test-dynamic-processor''' ,		token=self._token				)
                processor.save_pretrained(snake_case_				)

                # This has added the proper auto_map field to the feature extractor config
                self.assertDictEqual(
                    processor.feature_extractor.auto_map ,		{
                        """AutoFeatureExtractor""": """custom_feature_extraction.CustomFeatureExtractor""",
                        """AutoProcessor""": """custom_processing.CustomProcessor""",
                    } ,		)

                # This has added the proper auto_map field to the tokenizer config
                with open(os.path.join(snake_case_ ,		"""tokenizer_config.json"""				)				) as f:
                       UpperCAmelCase	    =			json.load(snake_case_				)
                self.assertDictEqual(
                    tokenizer_config["""auto_map"""] ,		{
                        """AutoTokenizer""": ["""custom_tokenization.CustomTokenizer""", None],
                        """AutoProcessor""": """custom_processing.CustomProcessor""",
                    } ,		)

                # The code has been copied from fixtures
                self.assertTrue(os.path.isfile(os.path.join(snake_case_ ,		"""custom_feature_extraction.py"""				)				)				)
                self.assertTrue(os.path.isfile(os.path.join(snake_case_ ,		"""custom_tokenization.py"""				)				)				)
                self.assertTrue(os.path.isfile(os.path.join(snake_case_ ,		"""custom_processing.py"""				)				)				)

                repo.push_to_hub()

         UpperCAmelCase	    =			AutoProcessor.from_pretrained(f'''{USER}/test-dynamic-processor''' ,		trust_remote_code=snake_case_				)
         # Can't make an isinstance check because the new_processor is from the CustomProcessor class of a dynamic module
         self.assertEqual(new_processor.__class__.__name__ ,		"""CustomProcessor"""				)








"""simple docstring"""







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   UpperCamelCase_ (       unittest.TestCase  ):



  def __init__(      self ,		snake_case__ ,		snake_case__ = True ,		snake_case__ = None ,		snake_case__ = 32 ,		snake_case__ = True ,		snake_case__ = 1 / 2_55 ,		snake_case__ = True ,		snake_case__ = True ,		snake_case__ = [0.48_145_466, 0.4_578_275, 0.40_821_073] ,		snake_case__ = [0.26_862_954, 0.26_130_258, 0.27_577_711] ,		snake_case__ = True ,		snake_case__=7 ,		snake_case__=30 ,		snake_case__=4_00 ,		snake_case__=3 ,		)			->			Union[str, Any]:



         """simple docstring"""





         UpperCAmelCase	    =			parent
         UpperCAmelCase	    =			do_resize
         UpperCAmelCase	    =			size if size is not None else {"""shortest_edge""": 2_88}
         UpperCAmelCase	    =			size_divisor
         UpperCAmelCase	    =			do_rescale
         UpperCAmelCase	    =			rescale_factor
         UpperCAmelCase	    =			do_normalize
         UpperCAmelCase	    =			do_center_crop
         UpperCAmelCase	    =			image_mean
         UpperCAmelCase	    =			image_std
         UpperCAmelCase	    =			do_pad
         UpperCAmelCase	    =			batch_size
         UpperCAmelCase	    =			num_channels
         UpperCAmelCase	    =			min_resolution
         UpperCAmelCase	    =			max_resolution



  def 		UpperCamelCase_				(      self				)			->			int:



         """simple docstring"""





         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 		UpperCamelCase_				(      self ,		snake_case__ ,		snake_case__=False				)			->			Optional[int]:



         """simple docstring"""





         if not batched:
                UpperCAmelCase	    =			self.size["""shortest_edge"""]
                UpperCAmelCase	    =			image_inputs[0]
                if isinstance(snake_case__ ,		Image.Image				):
                       UpperCAmelCase    ,       UpperCAmelCase	    =			image.size
                else:
                       UpperCAmelCase    ,       UpperCAmelCase	    =			image.shape[1], image.shape[2]
                UpperCAmelCase	    =			size / min(snake_case__ ,		snake_case__				)
                if h < w:
                       UpperCAmelCase    ,       UpperCAmelCase	    =			size, scale * w
                else:
                       UpperCAmelCase    ,       UpperCAmelCase	    =			scale * h, size

                UpperCAmelCase	    =			int((13_33 / 8_00) * size				)
                if max(snake_case__ ,		snake_case__				) > max_size:
                       UpperCAmelCase	    =			max_size / max(snake_case__ ,		snake_case__				)
                       UpperCAmelCase	    =			newh * scale
                       UpperCAmelCase	    =			neww * scale

                UpperCAmelCase    ,       UpperCAmelCase	    =			int(newh + 0.5				), int(neww + 0.5				)
                UpperCAmelCase    ,       UpperCAmelCase	    =			(
                    newh // self.size_divisor * self.size_divisor,
                    neww // self.size_divisor * self.size_divisor,
                )

         else:
                UpperCAmelCase	    =			[]
                for image in image_inputs:
                       UpperCAmelCase    ,       UpperCAmelCase	    =			self.get_expected_values([image]				)
                       expected_values.append((expected_height, expected_width)				)
                UpperCAmelCase	    =			max(snake_case__ ,		key=lambda snake_case__				: item[0]				)[0]
                UpperCAmelCase	    =			max(snake_case__ ,		key=lambda snake_case__				: item[1]				)[1]

         return expected_height, expected_width





@require_torch
@require_vision
class   UpperCamelCase_ (       a_   ,					unittest.TestCase  ):
  _A       :					int				=	BridgeTowerImageProcessor if is_vision_available() else None



  def 		UpperCamelCase_				(      self				)			->			str:



         """simple docstring"""





         UpperCAmelCase	    =			BridgeTowerImageProcessingTester(self				)



  @property
  def 		UpperCamelCase_				(      self				)			->			Dict:



         """simple docstring"""





         return self.image_processor_tester.prepare_image_processor_dict()



  def 		UpperCamelCase_				(      self				)			->			List[str]:



         """simple docstring"""





         UpperCAmelCase	    =			self.image_processing_class(**self.image_processor_dict				)
         self.assertTrue(hasattr(snake_case__ ,		"""image_mean"""				)				)
         self.assertTrue(hasattr(snake_case__ ,		"""image_std"""				)				)
         self.assertTrue(hasattr(snake_case__ ,		"""do_normalize"""				)				)
         self.assertTrue(hasattr(snake_case__ ,		"""do_resize"""				)				)
         self.assertTrue(hasattr(snake_case__ ,		"""size"""				)				)
         self.assertTrue(hasattr(snake_case__ ,		"""size_divisor"""				)				)



  def 		UpperCamelCase_				(      self				)			->			Union[str, Any]:



         """simple docstring"""





         pass



  def 		UpperCamelCase_				(      self				)			->			List[Any]:



         """simple docstring"""





         UpperCAmelCase	    =			self.image_processing_class(**self.image_processor_dict				)
         # create random PIL images
         UpperCAmelCase	    =			prepare_image_inputs(self.image_processor_tester ,		equal_resolution=snake_case__				)
         for image in image_inputs:
                self.assertIsInstance(snake_case__ ,		Image.Image				)

         # Test not batched input
         UpperCAmelCase	    =			image_processing(image_inputs[0] ,		return_tensors="""pt"""				).pixel_values

         UpperCAmelCase    ,       UpperCAmelCase	    =			self.image_processor_tester.get_expected_values(snake_case__				)
         self.assertEqual(
             encoded_images.shape ,		(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,		)

         # Test batched
         UpperCAmelCase	    =			image_processing(snake_case__ ,		return_tensors="""pt"""				).pixel_values

         UpperCAmelCase    ,       UpperCAmelCase	    =			self.image_processor_tester.get_expected_values(snake_case__ ,		batched=snake_case__				)
         self.assertEqual(
             encoded_images.shape ,		(
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             ) ,		)



  def 		UpperCamelCase_				(      self				)			->			int:



         """simple docstring"""





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

         # Test not batched input
         UpperCAmelCase	    =			image_processing(image_inputs[0] ,		return_tensors="""pt"""				).pixel_values

         UpperCAmelCase    ,       UpperCAmelCase	    =			self.image_processor_tester.get_expected_values(snake_case__				)
         self.assertEqual(
             encoded_images.shape ,		(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,		)

         # Test batched
         UpperCAmelCase	    =			image_processing(snake_case__ ,		return_tensors="""pt"""				).pixel_values

         UpperCAmelCase    ,       UpperCAmelCase	    =			self.image_processor_tester.get_expected_values(snake_case__ ,		batched=snake_case__				)
         self.assertEqual(
             encoded_images.shape ,		(
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             ) ,		)



  def 		UpperCamelCase_				(      self				)			->			Dict:



         """simple docstring"""





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

         # Test not batched input
         UpperCAmelCase	    =			image_processing(image_inputs[0] ,		return_tensors="""pt"""				).pixel_values

         UpperCAmelCase    ,       UpperCAmelCase	    =			self.image_processor_tester.get_expected_values(snake_case__				)
         self.assertEqual(
             encoded_images.shape ,		(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,		)

         # Test batched
         UpperCAmelCase	    =			image_processing(snake_case__ ,		return_tensors="""pt"""				).pixel_values

         UpperCAmelCase    ,       UpperCAmelCase	    =			self.image_processor_tester.get_expected_values(snake_case__ ,		batched=snake_case__				)
         self.assertEqual(
             encoded_images.shape ,		(
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             ) ,		)
