




import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     MODEL_FOR_PRETRAINING_MAPPING,
     MobileBertForMaskedLM,
     MobileBertForMultipleChoice,
     MobileBertForNextSentencePrediction,
     MobileBertForPreTraining,
     MobileBertForQuestionAnswering,
     MobileBertForSequenceClassification,
     MobileBertForTokenClassification,
     MobileBertModel,
 )







class   A:



 '''simple docstring'''


 def __init__(    self :  Dict						,							A_ :  Dict						,							A_ :  Optional[Any]=13						,							A_ :  List[Any]=7						,							A_ :  Any=True						,							A_ :  str=True						,							A_ :  Optional[int]=True						,							A_ :  Optional[int]=True						,							A_ :  Union[str, Any]=99						,							A_ :  Any=64						,							A_ :  Any=32						,							A_ :  List[str]=5						,							A_ :  List[str]=4						,							A_ :  Dict=37						,							A_ :  Union[str, Any]="gelu"						,							A_ :  Optional[Any]=0.1						,							A_ :  List[Any]=0.1						,							A_ :  Any=512						,							A_ :  List[Any]=16						,							A_ :  Any=2						,							A_ :  Any=0.02						,							A_ :  Optional[Any]=3						,							A_ :  int=4						,							A_ :  List[str]=None						,							)       ->     int:

       """simple docstring"""






       lowerCamelCase_							=   parent
       lowerCamelCase_							=   batch_size
       lowerCamelCase_							=   seq_length
       lowerCamelCase_							=   is_training
       lowerCamelCase_							=   use_input_mask
       lowerCamelCase_							=   use_token_type_ids
       lowerCamelCase_							=   use_labels
       lowerCamelCase_							=   vocab_size
       lowerCamelCase_							=   hidden_size
       lowerCamelCase_							=   embedding_size
       lowerCamelCase_							=   num_hidden_layers
       lowerCamelCase_							=   num_attention_heads
       lowerCamelCase_							=   intermediate_size
       lowerCamelCase_							=   hidden_act
       lowerCamelCase_							=   hidden_dropout_prob
       lowerCamelCase_							=   attention_probs_dropout_prob
       lowerCamelCase_							=   max_position_embeddings
       lowerCamelCase_							=   type_vocab_size
       lowerCamelCase_							=   type_sequence_label_size
       lowerCamelCase_							=   initializer_range
       lowerCamelCase_							=   num_labels
       lowerCamelCase_							=   num_choices
       lowerCamelCase_							=   scope

 def     a__			(    self :  Tuple  )       ->     str:

       """simple docstring"""






       lowerCamelCase_							=   ids_tensor([self.batch_size, self.seq_length]						,							self.vocab_size  )

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

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

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

       lowerCamelCase_							=   self.get_config()

       return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

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

       """simple docstring"""






       return 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						,							embedding_size=self.embedding_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						,							is_decoder=A_						,							initializer_range=self.initializer_range						,							)

 def     a__			(    self :  int						,							A_ :  Tuple						,							A_ :  Optional[Any]						,							A_ :  List[str]						,							A_ :  Union[str, Any]						,							A_ :  str						,							A_ :  Optional[Any]						,							A_ :  Dict  )       ->     Optional[Any]:

       """simple docstring"""






       lowerCamelCase_							=   MobileBertModel(config=A_  )
       model.to(A_  )
       model.eval()
       lowerCamelCase_							=   model(A_						,							attention_mask=A_						,							token_type_ids=A_  )
       lowerCamelCase_							=   model(A_						,							token_type_ids=A_  )
       lowerCamelCase_							=   model(A_  )

       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     a__			(    self :  Dict						,							A_ :  Optional[int]						,							A_ :  Dict						,							A_ :  Optional[Any]						,							A_ :  Union[str, Any]						,							A_ :  str						,							A_ :  int						,							A_ :  List[str]  )       ->     List[str]:

       """simple docstring"""






       lowerCamelCase_							=   MobileBertForMaskedLM(config=A_  )
       model.to(A_  )
       model.eval()
       lowerCamelCase_							=   model(A_						,							attention_mask=A_						,							token_type_ids=A_						,							labels=A_  )
       self.parent.assertEqual(result.logits.shape						,							(self.batch_size, self.seq_length, self.vocab_size)  )

 def     a__			(    self :  Dict						,							A_ :  List[str]						,							A_ :  List[str]						,							A_ :  Optional[int]						,							A_ :  Optional[Any]						,							A_ :  Optional[int]						,							A_ :  int						,							A_ :  Any  )       ->     Dict:

       """simple docstring"""






       lowerCamelCase_							=   MobileBertForNextSentencePrediction(config=A_  )
       model.to(A_  )
       model.eval()
       lowerCamelCase_							=   model(
           A_						,							attention_mask=A_						,							token_type_ids=A_						,							labels=A_						,							)
       self.parent.assertEqual(result.logits.shape						,							(self.batch_size, 2)  )

 def     a__			(    self :  int						,							A_ :  int						,							A_ :  List[str]						,							A_ :  Optional[Any]						,							A_ :  Any						,							A_ :  str						,							A_ :  Optional[Any]						,							A_ :  Tuple  )       ->     str:

       """simple docstring"""






       lowerCamelCase_							=   MobileBertForPreTraining(config=A_  )
       model.to(A_  )
       model.eval()
       lowerCamelCase_							=   model(
           A_						,							attention_mask=A_						,							token_type_ids=A_						,							labels=A_						,							next_sentence_label=A_						,							)
       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     a__			(    self :  Any						,							A_ :  int						,							A_ :  List[Any]						,							A_ :  Union[str, Any]						,							A_ :  Tuple						,							A_ :  List[str]						,							A_ :  Optional[int]						,							A_ :  int  )       ->     Optional[Any]:

       """simple docstring"""






       lowerCamelCase_							=   MobileBertForQuestionAnswering(config=A_  )
       model.to(A_  )
       model.eval()
       lowerCamelCase_							=   model(
           A_						,							attention_mask=A_						,							token_type_ids=A_						,							start_positions=A_						,							end_positions=A_						,							)
       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     a__			(    self :  Tuple						,							A_ :  Optional[Any]						,							A_ :  str						,							A_ :  List[Any]						,							A_ :  Any						,							A_ :  Union[str, Any]						,							A_ :  Optional[int]						,							A_ :  List[str]  )       ->     Dict:

       """simple docstring"""






       lowerCamelCase_							=   self.num_labels
       lowerCamelCase_							=   MobileBertForSequenceClassification(A_  )
       model.to(A_  )
       model.eval()
       lowerCamelCase_							=   model(A_						,							attention_mask=A_						,							token_type_ids=A_						,							labels=A_  )
       self.parent.assertEqual(result.logits.shape						,							(self.batch_size, self.num_labels)  )

 def     a__			(    self :  Union[str, Any]						,							A_ :  Tuple						,							A_ :  Union[str, Any]						,							A_ :  Optional[Any]						,							A_ :  Tuple						,							A_ :  List[Any]						,							A_ :  Any						,							A_ :  List[Any]  )       ->     Dict:

       """simple docstring"""






       lowerCamelCase_							=   self.num_labels
       lowerCamelCase_							=   MobileBertForTokenClassification(config=A_  )
       model.to(A_  )
       model.eval()
       lowerCamelCase_							=   model(A_						,							attention_mask=A_						,							token_type_ids=A_						,							labels=A_  )
       self.parent.assertEqual(result.logits.shape						,							(self.batch_size, self.seq_length, self.num_labels)  )

 def     a__			(    self :  Tuple						,							A_ :  int						,							A_ :  int						,							A_ :  Dict						,							A_ :  Dict						,							A_ :  Optional[Any]						,							A_ :  Dict						,							A_ :  Tuple  )       ->     Optional[int]:

       """simple docstring"""






       lowerCamelCase_							=   self.num_choices
       lowerCamelCase_							=   MobileBertForMultipleChoice(config=A_  )
       model.to(A_  )
       model.eval()
       lowerCamelCase_							=   input_ids.unsqueeze(1  ).expand(-1						,							self.num_choices						,							-1  ).contiguous()
       lowerCamelCase_							=   token_type_ids.unsqueeze(1  ).expand(-1						,							self.num_choices						,							-1  ).contiguous()
       lowerCamelCase_							=   input_mask.unsqueeze(1  ).expand(-1						,							self.num_choices						,							-1  ).contiguous()
       lowerCamelCase_							=   model(
           A_						,							attention_mask=A_						,							token_type_ids=A_						,							labels=A_						,							)
       self.parent.assertEqual(result.logits.shape						,							(self.batch_size, self.num_choices)  )





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

       """simple docstring"""






       lowerCamelCase_							=   self.prepare_config_and_inputs()
       (
           (
           lowerCamelCase_
       )					,    (
           lowerCamelCase_
       )					,    (
           lowerCamelCase_
       )					,    (
           lowerCamelCase_
       )					,    (
           lowerCamelCase_
       )					,    (
           lowerCamelCase_
       )					,    (
           lowerCamelCase_
       )					,    
       )							=   config_and_inputs
       lowerCamelCase_							=   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
       return config, inputs_dict







@require_torch
class   A(						UpperCamelCase							,				UpperCamelCase							,				unittest.TestCase       ):



 '''simple docstring'''


 UpperCamelCase						       =						(
     (
         MobileBertModel,
         MobileBertForMaskedLM,
         MobileBertForMultipleChoice,
         MobileBertForNextSentencePrediction,
         MobileBertForPreTraining,
         MobileBertForQuestionAnswering,
         MobileBertForSequenceClassification,
         MobileBertForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 UpperCamelCase						       =						(
     {
         '''feature-extraction''': MobileBertModel,
         '''fill-mask''': MobileBertForMaskedLM,
         '''question-answering''': MobileBertForQuestionAnswering,
         '''text-classification''': MobileBertForSequenceClassification,
         '''token-classification''': MobileBertForTokenClassification,
         '''zero-shot''': MobileBertForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 UpperCamelCase						       =						True

 def     a__			(    self :  Optional[Any]						,							A_ :  str						,							A_ :  Any						,							A_ :  Tuple=False  )       ->     List[Any]:

       """simple docstring"""






       lowerCamelCase_							=   super()._prepare_for_class(A_						,							A_						,							return_labels=A_  )

       if return_labels:
             if model_class in get_values(A_  ):
                   lowerCamelCase_							=   torch.zeros(
                       (self.model_tester.batch_size, self.model_tester.seq_length)						,							dtype=torch.long						,							device=A_  )
                   lowerCamelCase_							=   torch.zeros(
                       self.model_tester.batch_size						,							dtype=torch.long						,							device=A_  )
       return inputs_dict

 def     a__			(    self :  int  )       ->     Dict:

       """simple docstring"""






       lowerCamelCase_							=   MobileBertModelTester(self  )
       lowerCamelCase_							=   ConfigTester(self						,							config_class=A_						,							hidden_size=37  )

 def     a__			(    self :  Any  )       ->     Tuple:

       """simple docstring"""






       self.config_tester.run_common_tests()

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

       """simple docstring"""






       lowerCamelCase_							=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_model(*A_  )

 def     a__			(    self :  int  )       ->     str:

       """simple docstring"""






       lowerCamelCase_							=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_masked_lm(*A_  )

 def     a__			(    self :  Tuple  )       ->     int:

       """simple docstring"""






       lowerCamelCase_							=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_multiple_choice(*A_  )

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

       """simple docstring"""






       lowerCamelCase_							=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*A_  )

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

       """simple docstring"""






       lowerCamelCase_							=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_pretraining(*A_  )

 def     a__			(    self :  Dict  )       ->     str:

       """simple docstring"""






       lowerCamelCase_							=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_question_answering(*A_  )

 def     a__			(    self :  Tuple  )       ->     str:

       """simple docstring"""






       lowerCamelCase_							=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_sequence_classification(*A_  )





 def     a__			(    self :  Optional[Any]  )       ->     str:

       """simple docstring"""






       lowerCamelCase_							=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_token_classification(*A_  )

def       _SCREAMING_SNAKE_CASE      (							lowercase     :	Union[str, Any]					):


      '''simple docstring'''



      return torch.tensor(
          lowercase     ,							dtype=torch.long     ,							device=lowercase     ,							)


lowerCamelCase    :		str			   =       1e-3







@require_torch
@require_sentencepiece
@require_tokenizers
class   A(						unittest.TestCase       ):



 '''simple docstring'''


 @slow
 def     a__			(    self :  List[str]  )       ->     Union[str, Any]:

       """simple docstring"""






       lowerCamelCase_							=   MobileBertModel.from_pretrained('google/mobilebert-uncased'  ).to(A_  )
       lowerCamelCase_							=   _long_tensor([[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]]  )
       with torch.no_grad():
             lowerCamelCase_							=   model(A_  )[0]
       lowerCamelCase_							=   torch.Size((1, 9, 512)  )
       self.assertEqual(output.shape						,							A_  )
       lowerCamelCase_							=   torch.tensor(
           [
               [
                   [-2.4_736_526E07, 8.2_691_656E04, 1.6_521_838E05],
                   [-5.7_541_704E-01, 3.9_056_022E00, 4.4_011_507E00],
                   [2.6_047_359E00, 1.5_677_652E00, -1.7_324_188E-01],
               ]
           ]						,							device=A_						,							)

       # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
       # ~1 difference, it's therefore not a good idea to measure using addition.
       # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
       # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
       lowerCamelCase_							=   torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE  )
       lowerCamelCase_							=   torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE  )

       self.assertTrue(lower_bound and upper_bound  )









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       ):



 '''simple docstring'''


 def __init__(    self :  str						,							A_ :  int						,							A_ :  Any=7						,							A_ :  Tuple=3						,							A_ :  Union[str, Any]=18						,							A_ :  Tuple=30						,							A_ :  Union[str, Any]=400						,							A_ :  Optional[int]=True						,							A_ :  List[Any]=None						,							A_ :  Dict=True						,							A_ :  Union[str, Any]=None						,							A_ :  Optional[int]=True						,							A_ :  str=[0.48145466, 0.4578275, 0.40821073]						,							A_ :  Tuple=[0.26862954, 0.26130258, 0.27577711]						,							A_ :  Any=True						,							)       ->     str:

       """simple docstring"""






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

 def     a__			(    self :  Optional[int]  )       ->     Tuple:

       """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     a__			(    self :  Any						,							A_ :  Any=False						,							A_ :  Dict=False						,							A_ :  str=False  )       ->     Union[str, Any]:

       """simple docstring"""






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

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

       if torchify:
             lowerCamelCase_							=   [torch.from_numpy(A_  ) for x in image_inputs]

       return image_inputs







@require_torch
@require_vision
class   A(						UpperCamelCase							,				unittest.TestCase       ):



 '''simple docstring'''


 UpperCamelCase						       =						ChineseCLIPImageProcessor if is_vision_available() else None

 def     a__			(    self :  int  )       ->     Any:

       """simple docstring"""






       lowerCamelCase_							=   ChineseCLIPImageProcessingTester(self						,							do_center_crop=A_  )

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

       """simple docstring"""






       return self.image_processor_tester.prepare_image_processor_dict()

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

       """simple docstring"""






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

 def     a__			(    self :  Any  )       ->     Any:

       """simple docstring"""






       lowerCamelCase_							=   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}  )

       lowerCamelCase_							=   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     a__			(    self :  List[Any]  )       ->     List[Any]:

       """simple docstring"""






       pass

 def     a__			(    self :  str  )       ->     str:

       """simple docstring"""






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

       # Test not batched input
       lowerCamelCase_							=   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_							=   image_processing(A_						,							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     a__			(    self :  List[str]  )       ->     Optional[Any]:

       """simple docstring"""






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

       # Test not batched input
       lowerCamelCase_							=   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_							=   image_processing(A_						,							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     a__			(    self :  str  )       ->     Dict:

       """simple docstring"""






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

       # Test not batched input
       lowerCamelCase_							=   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_							=   image_processing(A_						,							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(						UpperCamelCase							,				unittest.TestCase       ):



 '''simple docstring'''


 UpperCamelCase						       =						ChineseCLIPImageProcessor if is_vision_available() else None

 def     a__			(    self :  Dict  )       ->     int:

       """simple docstring"""






       lowerCamelCase_							=   ChineseCLIPImageProcessingTester(self						,							num_channels=4						,							do_center_crop=A_  )
       lowerCamelCase_							=   3

 @property
 def     a__			(    self :  Any  )       ->     int:

       """simple docstring"""






       return self.image_processor_tester.prepare_image_processor_dict()

 def     a__			(    self :  Dict  )       ->     Tuple:

       """simple docstring"""






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

 def     a__			(    self :  Tuple  )       ->     List[str]:

       """simple docstring"""






       pass





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

       """simple docstring"""






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

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



