
from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers import (
						    TF_MODEL_FOR_PRETRAINING_MAPPING,
						    TFMobileBertForMaskedLM,
						    TFMobileBertForMultipleChoice,
						    TFMobileBertForNextSentencePrediction,
						    TFMobileBertForPreTraining,
						    TFMobileBertForQuestionAnswering,
						    TFMobileBertForSequenceClassification,
						    TFMobileBertForTokenClassification,
						    TFMobileBertModel,
						)
@require_tf
class  lowercase__(				UpperCAmelCase ,						UpperCAmelCase ,						unittest.TestCase							):



	"""simple docstring"""




	a			:Any         =	(
	    (
	        TFMobileBertModel,
	        TFMobileBertForMaskedLM,
	        TFMobileBertForNextSentencePrediction,
	        TFMobileBertForPreTraining,
	        TFMobileBertForQuestionAnswering,
	        TFMobileBertForSequenceClassification,
	        TFMobileBertForTokenClassification,
	        TFMobileBertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	a			:Dict         =	(
	    {
	        'feature-extraction': TFMobileBertModel,
	        'fill-mask': TFMobileBertForMaskedLM,
	        'question-answering': TFMobileBertForQuestionAnswering,
	        'text-classification': TFMobileBertForSequenceClassification,
	        'token-classification': TFMobileBertForTokenClassification,
	        'zero-shot': TFMobileBertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	a			:str         =	False
	a			:Any         =	False
	def 						_lowercase  (       self  :			str       ,							SCREAMING_SNAKE_CASE_  :			int       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=False       )       ->     Optional[int]:
					lowercase_       =					super()._prepare_for_class(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							return_labels=SCREAMING_SNAKE_CASE_       )

					if return_labels:
									if model_class in get_values(SCREAMING_SNAKE_CASE_       ):
													lowercase_       =					tf.zeros(self.model_tester.batch_size       ,							dtype=tf.intaa       )

					return inputs_dict
	class  lowercase__(				UpperCAmelCase							):



		"""simple docstring"""




		def __init__(       self  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			int=1_3       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=7       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=True       ,							SCREAMING_SNAKE_CASE_  :			Tuple=True       ,							SCREAMING_SNAKE_CASE_  :			List[str]=True       ,							SCREAMING_SNAKE_CASE_  :			str=True       ,							SCREAMING_SNAKE_CASE_  :			List[str]=9_9       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=3_2       ,							SCREAMING_SNAKE_CASE_  :			Tuple=3_2       ,							SCREAMING_SNAKE_CASE_  :			List[str]=2       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=4       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=3_7       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]="gelu"       ,							SCREAMING_SNAKE_CASE_  :			Tuple=0.1       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=0.1       ,							SCREAMING_SNAKE_CASE_  :			List[str]=5_1_2       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=1_6       ,							SCREAMING_SNAKE_CASE_  :			List[str]=2       ,							SCREAMING_SNAKE_CASE_  :			List[str]=0.02       ,							SCREAMING_SNAKE_CASE_  :			Any=3       ,							SCREAMING_SNAKE_CASE_  :			Any=4       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=None       ,							)       ->     Any:
						lowercase_       =					parent
						lowercase_       =					batch_size
						lowercase_       =					seq_length
						lowercase_       =					is_training
						lowercase_       =					use_input_mask
						lowercase_       =					use_token_type_ids
						lowercase_       =					use_labels
						lowercase_       =					vocab_size
						lowercase_       =					hidden_size
						lowercase_       =					num_hidden_layers
						lowercase_       =					num_attention_heads
						lowercase_       =					intermediate_size
						lowercase_       =					hidden_act
						lowercase_       =					hidden_dropout_prob
						lowercase_       =					attention_probs_dropout_prob
						lowercase_       =					max_position_embeddings
						lowercase_       =					type_vocab_size
						lowercase_       =					type_sequence_label_size
						lowercase_       =					initializer_range
						lowercase_       =					num_labels
						lowercase_       =					num_choices
						lowercase_       =					scope
						lowercase_       =					embedding_size
		def 						_lowercase  (       self  :			List[str]       )       ->     List[str]:
						lowercase_       =					ids_tensor([self.batch_size, self.seq_length]       ,							self.vocab_size       )

						lowercase_       =					None
						if self.use_input_mask:
										lowercase_       =					random_attention_mask([self.batch_size, self.seq_length]       )

						lowercase_       =					None
						if self.use_token_type_ids:
										lowercase_       =					ids_tensor([self.batch_size, self.seq_length]       ,							self.type_vocab_size       )

						lowercase_       =					None
						lowercase_       =					None
						lowercase_       =					None
						if self.use_labels:
										lowercase_       =					ids_tensor([self.batch_size]       ,							self.type_sequence_label_size       )
										lowercase_       =					ids_tensor([self.batch_size, self.seq_length]       ,							self.num_labels       )
										lowercase_       =					ids_tensor([self.batch_size]       ,							self.num_choices       )

						lowercase_       =					MobileBertConfig(
						    vocab_size=self.vocab_size       ,							hidden_size=self.hidden_size       ,							num_hidden_layers=self.num_hidden_layers       ,							num_attention_heads=self.num_attention_heads       ,							intermediate_size=self.intermediate_size       ,							hidden_act=self.hidden_act       ,							hidden_dropout_prob=self.hidden_dropout_prob       ,							attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,							max_position_embeddings=self.max_position_embeddings       ,							type_vocab_size=self.type_vocab_size       ,							initializer_range=self.initializer_range       ,							embedding_size=self.embedding_size       ,							)

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
		def 						_lowercase  (       self  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			str       )       ->     Tuple:
						lowercase_       =					TFMobileBertModel(config=SCREAMING_SNAKE_CASE_       )
						lowercase_       =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )

						lowercase_       =					[input_ids, input_mask]
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )

						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )

						self.parent.assertEqual(
						    result.last_hidden_state.shape       ,							(self.batch_size, self.seq_length, self.hidden_size)       )
						self.parent.assertEqual(result.pooler_output.shape       ,							(self.batch_size, self.hidden_size)       )
		def 						_lowercase  (       self  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       )       ->     Tuple:
						lowercase_       =					TFMobileBertForMaskedLM(config=SCREAMING_SNAKE_CASE_       )
						lowercase_       =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )
						self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.vocab_size)       )
		def 						_lowercase  (       self  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Tuple       )       ->     str:
						lowercase_       =					TFMobileBertForNextSentencePrediction(config=SCREAMING_SNAKE_CASE_       )
						lowercase_       =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )
						self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, 2)       )
		def 						_lowercase  (       self  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       )       ->     Optional[Any]:
						lowercase_       =					TFMobileBertForPreTraining(config=SCREAMING_SNAKE_CASE_       )
						lowercase_       =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )
						self.parent.assertEqual(
						    result.prediction_logits.shape       ,							(self.batch_size, self.seq_length, self.vocab_size)       )
						self.parent.assertEqual(result.seq_relationship_logits.shape       ,							(self.batch_size, 2)       )
		def 						_lowercase  (       self  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			int       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Any       )       ->     List[str]:
						lowercase_       =					self.num_labels
						lowercase_       =					TFMobileBertForSequenceClassification(config=SCREAMING_SNAKE_CASE_       )
						lowercase_       =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )
						self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_labels)       )
		def 						_lowercase  (       self  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			int       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       )       ->     str:
						lowercase_       =					self.num_choices
						lowercase_       =					TFMobileBertForMultipleChoice(config=SCREAMING_SNAKE_CASE_       )
						lowercase_       =					tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_       ,							1       )       ,							(1, self.num_choices, 1)       )
						lowercase_       =					tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_       ,							1       )       ,							(1, self.num_choices, 1)       )
						lowercase_       =					tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_       ,							1       )       ,							(1, self.num_choices, 1)       )
						lowercase_       =					{
						    '''input_ids''': multiple_choice_inputs_ids,
						    '''attention_mask''': multiple_choice_input_mask,
						    '''token_type_ids''': multiple_choice_token_type_ids,
						}
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )
						self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_choices)       )
		def 						_lowercase  (       self  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			int       ,							SCREAMING_SNAKE_CASE_  :			int       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Tuple       )       ->     Tuple:
						lowercase_       =					self.num_labels
						lowercase_       =					TFMobileBertForTokenClassification(config=SCREAMING_SNAKE_CASE_       )
						lowercase_       =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )
						self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.num_labels)       )
		def 						_lowercase  (       self  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       )       ->     str:
						lowercase_       =					TFMobileBertForQuestionAnswering(config=SCREAMING_SNAKE_CASE_       )
						lowercase_       =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
						lowercase_       =					model(SCREAMING_SNAKE_CASE_       )
						self.parent.assertEqual(result.start_logits.shape       ,							(self.batch_size, self.seq_length)       )
						self.parent.assertEqual(result.end_logits.shape       ,							(self.batch_size, self.seq_length)       )




		def 						_lowercase  (       self  :			Any       )       ->     List[str]:
						lowercase_       =					self.prepare_config_and_inputs()
						(
						    (
						    lowercase_
						)  ,	(
						    lowercase_
						)  ,	(
						    lowercase_
						)  ,	(
						    lowercase_
						)  ,	(
						    lowercase_
						)  ,	(
						    lowercase_
						)  ,	(
						    lowercase_
						)  ,	
						)       =					config_and_inputs
						lowercase_       =					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
						return config, inputs_dict

	def 						_lowercase  (       self  :			int       )       ->     List[str]:
					lowercase_       =					TFMobileBertModelTest.TFMobileBertModelTester(self       )
					lowercase_       =					ConfigTester(self       ,							config_class=SCREAMING_SNAKE_CASE_       ,							hidden_size=3_7       )
	def 						_lowercase  (       self  :			List[str]       )       ->     Dict:
					self.config_tester.run_common_tests()
	def 						_lowercase  (       self  :			Optional[int]       )       ->     List[str]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_model(*SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			Any       )       ->     List[Any]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_masked_lm(*SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			Optional[Any]       )       ->     Tuple:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_multiple_choice(*SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			Any       )       ->     Optional[int]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			List[str]       )       ->     Optional[Any]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_pretraining(*SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			List[Any]       )       ->     Tuple:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_question_answering(*SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			Union[str, Any]       )       ->     str:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_sequence_classification(*SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			List[str]       )       ->     Dict:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_token_classification(*SCREAMING_SNAKE_CASE_       )




	@slow
	def 						_lowercase  (       self  :			Dict       )       ->     Any:
					# for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					for model_name in ["google/mobilebert-uncased"]:
									lowercase_       =					TFMobileBertModel.from_pretrained(SCREAMING_SNAKE_CASE_       )
									self.assertIsNotNone(SCREAMING_SNAKE_CASE_       )

@require_tf
class  lowercase__(				unittest.TestCase							):



	"""simple docstring"""




	@slow
	def 						_lowercase  (       self  :			str       )       ->     Optional[Any]:
					lowercase_       =					TFMobileBertForPreTraining.from_pretrained('''google/mobilebert-uncased'''       )
					lowercase_       =					tf.constant([[0, 1, 2, 3, 4, 5]]       )
					lowercase_       =					model(SCREAMING_SNAKE_CASE_       )[0]

					lowercase_       =					[1, 6, 3_0_5_2_2]
					self.assertEqual(output.shape       ,							SCREAMING_SNAKE_CASE_       )

					lowercase_       =					tf.constant(
					    [
					        [
					            [-4.5_91_95_47, -9.24_82_95, -9.64_52_56],
					            [-6.7_30_61_75, -6.44_02_84, -6.6_05_28_37],
					            [-7.2_74_35_06, -6.7_84_79_15, -6.02_46_73],
					        ]
					    ]       )
					tf.debugging.assert_near(output[:, :3, :3]       ,							SCREAMING_SNAKE_CASE_       ,							atol=1e-4       )











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, prepare_image_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import PoolFormerImageProcessor



class    _SCREAMING_SNAKE_CASE						(	unittest.TestCase    ):







 '''simple docstring'''

 def __init__(self				:   List[Any]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Dict=7       , UpperCAmelCase_				:   List[str]=3       , UpperCAmelCase_				:   str=30       , UpperCAmelCase_				:   List[str]=400       , UpperCAmelCase_				:   Optional[int]=True       , UpperCAmelCase_				:   Optional[int]=None       , UpperCAmelCase_				:   Tuple=0.9       , UpperCAmelCase_				:   str=None       , UpperCAmelCase_				:   int=True       , UpperCAmelCase_				:   Union[str, Any]=[0.5, 0.5, 0.5]       , UpperCAmelCase_				:   Optional[Any]=[0.5, 0.5, 0.5]       , )       ->str:



   '''simple docstring'''



   lowerCamelCase__:      List[Any]			  =size if size is not None else {"shortest_edge": 30}
   lowerCamelCase__:      Dict			  =crop_size if crop_size is not None else {"height": 30, "width": 30}
   lowerCamelCase__:      Any			  =parent
   lowerCamelCase__:      Any			  =batch_size
   lowerCamelCase__:      Optional[Any]			  =num_channels
   lowerCamelCase__:      Tuple			  =min_resolution
   lowerCamelCase__:      Union[str, Any]			  =max_resolution
   lowerCamelCase__:      Union[str, Any]			  =do_resize_and_center_crop
   lowerCamelCase__:      Optional[int]			  =size
   lowerCamelCase__:      str			  =crop_pct
   lowerCamelCase__:      Any			  =crop_size
   lowerCamelCase__:      List[str]			  =do_normalize
   lowerCamelCase__:      List[str]			  =image_mean
   lowerCamelCase__:      Tuple			  =image_std







 def 							SCREAMING_SNAKE_CASE_					(self				:   List[Any])       ->Optional[int]:



   '''simple docstring'''



   return {
       "size": self.size,
       "do_resize_and_center_crop": self.do_resize_and_center_crop,
       "crop_pct": self.crop_pct,
       "crop_size": self.crop_size,
       "do_normalize": self.do_normalize,
       "image_mean": self.image_mean,
       "image_std": self.image_std,
   }



@require_torch
@require_vision
class    _SCREAMING_SNAKE_CASE						(	__SCREAMING_SNAKE_CASE    ,							unittest.TestCase    ):







 '''simple docstring'''
 lowercase_		=			PoolFormerImageProcessor if is_vision_available() else None

 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[int])       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =PoolFormerImageProcessingTester(self)

 @property
 def 							SCREAMING_SNAKE_CASE_					(self				:   str)       ->int:



   '''simple docstring'''



   return self.image_processor_tester.prepare_image_processor_dict()

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



   '''simple docstring'''



   lowerCamelCase__:      Any			  =self.image_processing_class(**self.image_processor_dict)
   self.assertTrue(hasattr(UpperCAmelCase_       , "do_resize_and_center_crop"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "size"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "crop_pct"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "do_normalize"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "image_mean"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "image_std"))

 def 							SCREAMING_SNAKE_CASE_					(self				:   Any)       ->List[str]:



   '''simple docstring'''



   lowerCamelCase__:      List[str]			  =self.image_processing_class.from_dict(self.image_processor_dict)
   self.assertEqual(image_processor.size       , {"shortest_edge": 30})
   self.assertEqual(image_processor.crop_size       , {"height": 30, "width": 30})

   lowerCamelCase__:      Union[str, Any]			  =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 							SCREAMING_SNAKE_CASE_					(self				:   int)       ->Optional[Any]:



   '''simple docstring'''



   pass

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



   '''simple docstring'''



   lowerCamelCase__:      Union[str, Any]			  =self.image_processing_class(**self.image_processor_dict)
   # create random PIL images
   lowerCamelCase__:      Union[str, Any]			  =prepare_image_inputs(self.image_processor_tester       , equal_resolution=UpperCAmelCase_)
   for image in image_inputs:
     self.assertIsInstance(UpperCAmelCase_       , Image.Image)

   # Test not batched input
   lowerCamelCase__:      Dict			  =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
   lowerCamelCase__:      int			  =image_processing(UpperCAmelCase_       , 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 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Dict:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =self.image_processing_class(**self.image_processor_dict)
   # create random numpy tensors
   lowerCamelCase__:      Tuple			  =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
   lowerCamelCase__:      Union[str, Any]			  =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
   lowerCamelCase__:      List[str]			  =image_processing(UpperCAmelCase_       , 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 							SCREAMING_SNAKE_CASE_					(self				:   Union[str, Any])       ->Any:



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =self.image_processing_class(**self.image_processor_dict)
   # create random PyTorch tensors
   lowerCamelCase__:      Any			  =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
   lowerCamelCase__:      Any			  =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
   lowerCamelCase__:      str			  =image_processing(UpperCAmelCase_       , 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"],
       )       , )

