




'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


UpperCAmelCase_    :					Any					      =						{
    '''auto_factory''': ['''get_values'''],
    '''configuration_auto''': ['''ALL_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''CONFIG_MAPPING''', '''MODEL_NAMES_MAPPING''', '''AutoConfig'''],
    '''feature_extraction_auto''': ['''FEATURE_EXTRACTOR_MAPPING''', '''AutoFeatureExtractor'''],
    '''image_processing_auto''': ['''IMAGE_PROCESSOR_MAPPING''', '''AutoImageProcessor'''],
    '''processing_auto''': ['''PROCESSOR_MAPPING''', '''AutoProcessor'''],
    '''tokenization_auto''': ['''TOKENIZER_MAPPING''', '''AutoTokenizer'''],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCAmelCase_    :					Dict					      =						[
         '''MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING''',
         '''MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING''',
         '''MODEL_FOR_AUDIO_XVECTOR_MAPPING''',
         '''MODEL_FOR_BACKBONE_MAPPING''',
         '''MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING''',
         '''MODEL_FOR_CAUSAL_LM_MAPPING''',
         '''MODEL_FOR_CTC_MAPPING''',
         '''MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING''',
         '''MODEL_FOR_DEPTH_ESTIMATION_MAPPING''',
         '''MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING''',
         '''MODEL_FOR_IMAGE_SEGMENTATION_MAPPING''',
         '''MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING''',
         '''MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING''',
         '''MODEL_FOR_MASKED_LM_MAPPING''',
         '''MODEL_FOR_MASK_GENERATION_MAPPING''',
         '''MODEL_FOR_MULTIPLE_CHOICE_MAPPING''',
         '''MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING''',
         '''MODEL_FOR_OBJECT_DETECTION_MAPPING''',
         '''MODEL_FOR_PRETRAINING_MAPPING''',
         '''MODEL_FOR_QUESTION_ANSWERING_MAPPING''',
         '''MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING''',
         '''MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING''',
         '''MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING''',
         '''MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING''',
         '''MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING''',
         '''MODEL_FOR_TEXT_ENCODING_MAPPING''',
         '''MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING''',
         '''MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING''',
         '''MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING''',
         '''MODEL_FOR_VISION_2_SEQ_MAPPING''',
         '''MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING''',
         '''MODEL_MAPPING''',
         '''MODEL_WITH_LM_HEAD_MAPPING''',
         '''MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING''',
         '''MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING''',
         '''AutoModel''',
         '''AutoBackbone''',
         '''AutoModelForAudioClassification''',
         '''AutoModelForAudioFrameClassification''',
         '''AutoModelForAudioXVector''',
         '''AutoModelForCausalLM''',
         '''AutoModelForCTC''',
         '''AutoModelForDepthEstimation''',
         '''AutoModelForImageClassification''',
         '''AutoModelForImageSegmentation''',
         '''AutoModelForInstanceSegmentation''',
         '''AutoModelForMaskGeneration''',
         '''AutoModelForTextEncoding''',
         '''AutoModelForMaskedImageModeling''',
         '''AutoModelForMaskedLM''',
         '''AutoModelForMultipleChoice''',
         '''AutoModelForNextSentencePrediction''',
         '''AutoModelForObjectDetection''',
         '''AutoModelForPreTraining''',
         '''AutoModelForQuestionAnswering''',
         '''AutoModelForSemanticSegmentation''',
         '''AutoModelForSeq2SeqLM''',
         '''AutoModelForSequenceClassification''',
         '''AutoModelForSpeechSeq2Seq''',
         '''AutoModelForTableQuestionAnswering''',
         '''AutoModelForTokenClassification''',
         '''AutoModelForUniversalSegmentation''',
         '''AutoModelForVideoClassification''',
         '''AutoModelForVision2Seq''',
         '''AutoModelForVisualQuestionAnswering''',
         '''AutoModelForDocumentQuestionAnswering''',
         '''AutoModelWithLMHead''',
         '''AutoModelForZeroShotImageClassification''',
         '''AutoModelForZeroShotObjectDetection''',
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCAmelCase_    :					Union[str, Any]					      =						[
         '''TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING''',
         '''TF_MODEL_FOR_CAUSAL_LM_MAPPING''',
         '''TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING''',
         '''TF_MODEL_FOR_MASK_GENERATION_MAPPING''',
         '''TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING''',
         '''TF_MODEL_FOR_MASKED_LM_MAPPING''',
         '''TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING''',
         '''TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING''',
         '''TF_MODEL_FOR_PRETRAINING_MAPPING''',
         '''TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING''',
         '''TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING''',
         '''TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING''',
         '''TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING''',
         '''TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING''',
         '''TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING''',
         '''TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING''',
         '''TF_MODEL_FOR_TEXT_ENCODING_MAPPING''',
         '''TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING''',
         '''TF_MODEL_FOR_VISION_2_SEQ_MAPPING''',
         '''TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING''',
         '''TF_MODEL_MAPPING''',
         '''TF_MODEL_WITH_LM_HEAD_MAPPING''',
         '''TFAutoModel''',
         '''TFAutoModelForAudioClassification''',
         '''TFAutoModelForCausalLM''',
         '''TFAutoModelForImageClassification''',
         '''TFAutoModelForMaskedImageModeling''',
         '''TFAutoModelForMaskedLM''',
         '''TFAutoModelForMaskGeneration''',
         '''TFAutoModelForMultipleChoice''',
         '''TFAutoModelForNextSentencePrediction''',
         '''TFAutoModelForPreTraining''',
         '''TFAutoModelForDocumentQuestionAnswering''',
         '''TFAutoModelForQuestionAnswering''',
         '''TFAutoModelForSemanticSegmentation''',
         '''TFAutoModelForSeq2SeqLM''',
         '''TFAutoModelForSequenceClassification''',
         '''TFAutoModelForSpeechSeq2Seq''',
         '''TFAutoModelForTableQuestionAnswering''',
         '''TFAutoModelForTextEncoding''',
         '''TFAutoModelForTokenClassification''',
         '''TFAutoModelForVision2Seq''',
         '''TFAutoModelForZeroShotImageClassification''',
         '''TFAutoModelWithLMHead''',
     ]

try:
     if not is_flax_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCAmelCase_    :					Optional[int]					      =						[
         '''FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING''',
         '''FLAX_MODEL_FOR_CAUSAL_LM_MAPPING''',
         '''FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING''',
         '''FLAX_MODEL_FOR_MASKED_LM_MAPPING''',
         '''FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING''',
         '''FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING''',
         '''FLAX_MODEL_FOR_PRETRAINING_MAPPING''',
         '''FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING''',
         '''FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING''',
         '''FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING''',
         '''FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING''',
         '''FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING''',
         '''FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING''',
         '''FLAX_MODEL_MAPPING''',
         '''FlaxAutoModel''',
         '''FlaxAutoModelForCausalLM''',
         '''FlaxAutoModelForImageClassification''',
         '''FlaxAutoModelForMaskedLM''',
         '''FlaxAutoModelForMultipleChoice''',
         '''FlaxAutoModelForNextSentencePrediction''',
         '''FlaxAutoModelForPreTraining''',
         '''FlaxAutoModelForQuestionAnswering''',
         '''FlaxAutoModelForSeq2SeqLM''',
         '''FlaxAutoModelForSequenceClassification''',
         '''FlaxAutoModelForSpeechSeq2Seq''',
         '''FlaxAutoModelForTokenClassification''',
         '''FlaxAutoModelForVision2Seq''',
     ]


if TYPE_CHECKING:
     from .auto_factory import get_values
     from .configuration_auto import ALL_PRETRAINED_CONFIG_ARCHIVE_MAP, CONFIG_MAPPING, MODEL_NAMES_MAPPING, AutoConfig
     from .feature_extraction_auto import FEATURE_EXTRACTOR_MAPPING, AutoFeatureExtractor
     from .image_processing_auto import IMAGE_PROCESSOR_MAPPING, AutoImageProcessor
     from .processing_auto import PROCESSOR_MAPPING, AutoProcessor
     from .tokenization_auto import TOKENIZER_MAPPING, AutoTokenizer

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_auto import (
              MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
              MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING,
              MODEL_FOR_AUDIO_XVECTOR_MAPPING,
              MODEL_FOR_BACKBONE_MAPPING,
              MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING,
              MODEL_FOR_CAUSAL_LM_MAPPING,
              MODEL_FOR_CTC_MAPPING,
              MODEL_FOR_DEPTH_ESTIMATION_MAPPING,
              MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING,
              MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
              MODEL_FOR_IMAGE_SEGMENTATION_MAPPING,
              MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING,
              MODEL_FOR_MASK_GENERATION_MAPPING,
              MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING,
              MODEL_FOR_MASKED_LM_MAPPING,
              MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
              MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
              MODEL_FOR_OBJECT_DETECTION_MAPPING,
              MODEL_FOR_PRETRAINING_MAPPING,
              MODEL_FOR_QUESTION_ANSWERING_MAPPING,
              MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING,
              MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
              MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
              MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
              MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
              MODEL_FOR_TEXT_ENCODING_MAPPING,
              MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
              MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING,
              MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
              MODEL_FOR_VISION_2_SEQ_MAPPING,
              MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING,
              MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING,
              MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING,
              MODEL_MAPPING,
              MODEL_WITH_LM_HEAD_MAPPING,
              AutoBackbone,
              AutoModel,
              AutoModelForAudioClassification,
              AutoModelForAudioFrameClassification,
              AutoModelForAudioXVector,
              AutoModelForCausalLM,
              AutoModelForCTC,
              AutoModelForDepthEstimation,
              AutoModelForDocumentQuestionAnswering,
              AutoModelForImageClassification,
              AutoModelForImageSegmentation,
              AutoModelForInstanceSegmentation,
              AutoModelForMaskedImageModeling,
              AutoModelForMaskedLM,
              AutoModelForMaskGeneration,
              AutoModelForMultipleChoice,
              AutoModelForNextSentencePrediction,
              AutoModelForObjectDetection,
              AutoModelForPreTraining,
              AutoModelForQuestionAnswering,
              AutoModelForSemanticSegmentation,
              AutoModelForSeqaSeqLM,
              AutoModelForSequenceClassification,
              AutoModelForSpeechSeqaSeq,
              AutoModelForTableQuestionAnswering,
              AutoModelForTextEncoding,
              AutoModelForTokenClassification,
              AutoModelForUniversalSegmentation,
              AutoModelForVideoClassification,
              AutoModelForVisionaSeq,
              AutoModelForVisualQuestionAnswering,
              AutoModelForZeroShotImageClassification,
              AutoModelForZeroShotObjectDetection,
              AutoModelWithLMHead,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_auto import (
              TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
              TF_MODEL_FOR_CAUSAL_LM_MAPPING,
              TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING,
              TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
              TF_MODEL_FOR_MASK_GENERATION_MAPPING,
              TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING,
              TF_MODEL_FOR_MASKED_LM_MAPPING,
              TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
              TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
              TF_MODEL_FOR_PRETRAINING_MAPPING,
              TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
              TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING,
              TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
              TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
              TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
              TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
              TF_MODEL_FOR_TEXT_ENCODING_MAPPING,
              TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
              TF_MODEL_FOR_VISION_2_SEQ_MAPPING,
              TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING,
              TF_MODEL_MAPPING,
              TF_MODEL_WITH_LM_HEAD_MAPPING,
              TFAutoModel,
              TFAutoModelForAudioClassification,
              TFAutoModelForCausalLM,
              TFAutoModelForDocumentQuestionAnswering,
              TFAutoModelForImageClassification,
              TFAutoModelForMaskedImageModeling,
              TFAutoModelForMaskedLM,
              TFAutoModelForMaskGeneration,
              TFAutoModelForMultipleChoice,
              TFAutoModelForNextSentencePrediction,
              TFAutoModelForPreTraining,
              TFAutoModelForQuestionAnswering,
              TFAutoModelForSemanticSegmentation,
              TFAutoModelForSeqaSeqLM,
              TFAutoModelForSequenceClassification,
              TFAutoModelForSpeechSeqaSeq,
              TFAutoModelForTableQuestionAnswering,
              TFAutoModelForTextEncoding,
              TFAutoModelForTokenClassification,
              TFAutoModelForVisionaSeq,
              TFAutoModelForZeroShotImageClassification,
              TFAutoModelWithLMHead,
          )

     try:
          if not is_flax_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_flax_auto import (
              FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
              FLAX_MODEL_FOR_CAUSAL_LM_MAPPING,
              FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
              FLAX_MODEL_FOR_MASKED_LM_MAPPING,
              FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
              FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
              FLAX_MODEL_FOR_PRETRAINING_MAPPING,
              FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
              FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
              FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
              FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
              FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
              FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING,
              FLAX_MODEL_MAPPING,
              FlaxAutoModel,
              FlaxAutoModelForCausalLM,
              FlaxAutoModelForImageClassification,
              FlaxAutoModelForMaskedLM,
              FlaxAutoModelForMultipleChoice,
              FlaxAutoModelForNextSentencePrediction,
              FlaxAutoModelForPreTraining,
              FlaxAutoModelForQuestionAnswering,
              FlaxAutoModelForSeqaSeqLM,
              FlaxAutoModelForSequenceClassification,
              FlaxAutoModelForSpeechSeqaSeq,
              FlaxAutoModelForTokenClassification,
              FlaxAutoModelForVisionaSeq,
          )

else:
     import sys

     UpperCAmelCase_    :					Union[str, Any]					      =						_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)












'''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 CLIPImageProcessor





class       lowerCAmelCase				(	unittest.TestCase):


       def __init__(				self      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE=7      ,					__SCREAMING_SNAKE_CASE=3      ,					__SCREAMING_SNAKE_CASE=18      ,					__SCREAMING_SNAKE_CASE=30      ,					__SCREAMING_SNAKE_CASE=400      ,					__SCREAMING_SNAKE_CASE=True      ,					__SCREAMING_SNAKE_CASE=None      ,					__SCREAMING_SNAKE_CASE=True      ,					__SCREAMING_SNAKE_CASE=None      ,					__SCREAMING_SNAKE_CASE=True      ,					__SCREAMING_SNAKE_CASE=[0.48_145_466, 0.4_578_275, 0.40_821_073]      ,					__SCREAMING_SNAKE_CASE=[0.26_862_954, 0.26_130_258, 0.27_577_711]      ,					__SCREAMING_SNAKE_CASE=True      ,					) ->					Optional[Any]:



            '''simple docstring'''




            __snake_case         =					size if size is not None else {'''shortest_edge''': 20}
            __snake_case         =					crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
            __snake_case         =					parent
            __snake_case         =					batch_size
            __snake_case         =					num_channels
            __snake_case         =					image_size
            __snake_case         =					min_resolution
            __snake_case         =					max_resolution
            __snake_case         =					do_resize
            __snake_case         =					size
            __snake_case         =					do_center_crop
            __snake_case         =					crop_size
            __snake_case         =					do_normalize
            __snake_case         =					image_mean
            __snake_case         =					image_std
            __snake_case         =					do_convert_rgb


       def  lowerCAmelCase (				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  lowerCAmelCase (				self      ,					__SCREAMING_SNAKE_CASE=False      ,					__SCREAMING_SNAKE_CASE=False      ,					__SCREAMING_SNAKE_CASE=False					) ->					str:



            '''simple docstring'''




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

            if equal_resolution:
                 __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:
                 __snake_case         =					[]
                 for i in range(self.batch_size					):
                      __snake_case   ,      __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
                 __snake_case         =					[Image.fromarray(np.moveaxis(__SCREAMING_SNAKE_CASE      ,					0      ,					-1					)					) for x in image_inputs]

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

            return image_inputs





@require_torch
@require_vision
class       lowerCAmelCase				(	__lowerCAmelCase			,				unittest.TestCase):
       __lowercase					: Dict	    =     CLIPImageProcessor if is_vision_available() else None


       def  lowerCAmelCase (				self					) ->					int:



            '''simple docstring'''




            __snake_case         =					CLIPImageProcessingTester(self					)


       @property
       def  lowerCAmelCase (				self					) ->					List[str]:



            '''simple docstring'''




            return self.image_processor_tester.prepare_image_processor_dict()


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



            '''simple docstring'''




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


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



            '''simple docstring'''




            __snake_case         =					self.image_processing_class.from_dict(self.image_processor_dict					)
            self.assertEqual(image_processor.size      ,					{'''shortest_edge''': 20}					)
            self.assertEqual(image_processor.crop_size      ,					{'''height''': 18, '''width''': 18}					)

            __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  lowerCAmelCase (				self					) ->					Dict:



            '''simple docstring'''




            pass


       def  lowerCAmelCase (				self					) ->					str:



            '''simple docstring'''




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

            # Test not batched input
            __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
            __snake_case         =					image_processing(__SCREAMING_SNAKE_CASE      ,					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  lowerCAmelCase (				self					) ->					Dict:



            '''simple docstring'''




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

            # Test not batched input
            __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
            __snake_case         =					image_processing(__SCREAMING_SNAKE_CASE      ,					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  lowerCAmelCase (				self					) ->					int:



            '''simple docstring'''




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

            # Test not batched input
            __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
            __snake_case         =					image_processing(__SCREAMING_SNAKE_CASE      ,					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       lowerCAmelCase				(	__lowerCAmelCase			,				unittest.TestCase):
       __lowercase					: Dict	    =     CLIPImageProcessor if is_vision_available() else None


       def  lowerCAmelCase (				self					) ->					Any:



            '''simple docstring'''




            __snake_case         =					CLIPImageProcessingTester(self      ,					num_channels=4					)
            __snake_case         =					3


       @property
       def  lowerCAmelCase (				self					) ->					str:



            '''simple docstring'''




            return self.image_processor_tester.prepare_image_processor_dict()


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



            '''simple docstring'''




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


       def  lowerCAmelCase (				self					) ->					Tuple:



            '''simple docstring'''




            pass




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



            '''simple docstring'''




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

            # Test not batched input
            __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
            __snake_case         =					image_processing(__SCREAMING_SNAKE_CASE      ,					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'''],
                )      ,					)






