

"""simple docstring"""




import os
import tempfile
import unittest

from transformers import DistilBertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, 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 (
						    DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    DistilBertForMaskedLM,
						    DistilBertForMultipleChoice,
						    DistilBertForQuestionAnswering,
						    DistilBertForSequenceClassification,
						    DistilBertForTokenClassification,
						    DistilBertModel,
						)





class  lowerCamelCase    (A__      ):

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

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     List[Any]:
						SCREAMING_SNAKE_CASE__										=   ids_tensor([self.batch_size, self.seq_length]     ,					self.vocab_size							)

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

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

						SCREAMING_SNAKE_CASE__										=   self.get_config()

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

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     List[str]:
						return DistilBertConfig(
						    vocab_size=self.vocab_size     ,					dim=self.hidden_size     ,					n_layers=self.num_hidden_layers     ,					n_heads=self.num_attention_heads     ,					hidden_dim=self.intermediate_size     ,					hidden_act=self.hidden_act     ,					dropout=self.hidden_dropout_prob     ,					attention_dropout=self.attention_probs_dropout_prob     ,					max_position_embeddings=self.max_position_embeddings     ,					initializer_range=self.initializer_range     ,					)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    List[str]     ,					__UpperCAmelCase					:    Any							) ->     Dict:
						SCREAMING_SNAKE_CASE__										=   DistilBertModel(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase							)
						self.parent.assertEqual(result.last_hidden_state.shape     ,					(self.batch_size, self.seq_length, self.hidden_size)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    int     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    Tuple							) ->     Optional[int]:
						SCREAMING_SNAKE_CASE__										=   DistilBertForMaskedLM(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					labels=__UpperCAmelCase							)
						self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.seq_length, self.vocab_size)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[int]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    List[Any]     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    Optional[Any]							) ->     int:
						SCREAMING_SNAKE_CASE__										=   DistilBertForQuestionAnswering(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(
						    __UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					start_positions=__UpperCAmelCase     ,					end_positions=__UpperCAmelCase							)
						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        SCREAMING_SNAKE_CASE					(       self					:    Tuple     ,					__UpperCAmelCase					:    int     ,					__UpperCAmelCase					:    List[str]     ,					__UpperCAmelCase					:    List[Any]     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    Optional[Any]							) ->     List[str]:
						SCREAMING_SNAKE_CASE__										=   self.num_labels
						SCREAMING_SNAKE_CASE__										=   DistilBertForSequenceClassification(__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					labels=__UpperCAmelCase							)
						self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.num_labels)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[Any]     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    Dict     ,					__UpperCAmelCase					:    Optional[int]     ,					__UpperCAmelCase					:    Any							) ->     Any:
						SCREAMING_SNAKE_CASE__										=   self.num_labels
						SCREAMING_SNAKE_CASE__										=   DistilBertForTokenClassification(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()

						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					labels=__UpperCAmelCase							)
						self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.seq_length, self.num_labels)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Dict     ,					__UpperCAmelCase					:    int     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    Union[str, Any]							) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   self.num_choices
						SCREAMING_SNAKE_CASE__										=   DistilBertForMultipleChoice(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   input_ids.unsqueeze(1							).expand(-1     ,					self.num_choices     ,					-1							).contiguous()
						SCREAMING_SNAKE_CASE__										=   input_mask.unsqueeze(1							).expand(-1     ,					self.num_choices     ,					-1							).contiguous()
						SCREAMING_SNAKE_CASE__										=   model(
						    __UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					labels=__UpperCAmelCase     ,					)
						self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.num_choices)							)





			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     List[str]:
						SCREAMING_SNAKE_CASE__										=   self.prepare_config_and_inputs()
						((SCREAMING_SNAKE_CASE__)				,		(SCREAMING_SNAKE_CASE__)				,		(SCREAMING_SNAKE_CASE__)				,		(SCREAMING_SNAKE_CASE__)				,		(SCREAMING_SNAKE_CASE__)				,		(SCREAMING_SNAKE_CASE__))										=   config_and_inputs
						SCREAMING_SNAKE_CASE__										=   {"""input_ids""": input_ids, """attention_mask""": input_mask}
						return config, inputs_dict





@require_torch
class  lowerCamelCase    (A__      ,A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		str       		=				(
			    (
			        DistilBertModel,
			        DistilBertForMaskedLM,
			        DistilBertForMultipleChoice,
			        DistilBertForQuestionAnswering,
			        DistilBertForSequenceClassification,
			        DistilBertForTokenClassification,
			    )
			    if is_torch_available()
			    else None
			)
			lowerCamelCase__ :		List[Any]       		=				(
			    {
			        'feature-extraction': DistilBertModel,
			        'fill-mask': DistilBertForMaskedLM,
			        'question-answering': DistilBertForQuestionAnswering,
			        'text-classification': DistilBertForSequenceClassification,
			        'token-classification': DistilBertForTokenClassification,
			        'zero-shot': DistilBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			lowerCamelCase__ :		Union[str, Any]       		=				True
			lowerCamelCase__ :		Optional[Any]       		=				True
			lowerCamelCase__ :		int       		=				True
			lowerCamelCase__ :		List[str]       		=				True

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     Optional[int]:
						SCREAMING_SNAKE_CASE__										=   DistilBertModelTester(self							)
						SCREAMING_SNAKE_CASE__										=   ConfigTester(self     ,					config_class=__UpperCAmelCase     ,					dim=3_7							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     int:
						self.config_tester.run_common_tests()

			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[int]							) ->     str:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_distilbert_model(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    str							) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_distilbert_for_masked_lm(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]							) ->     Dict:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_distilbert_for_question_answering(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     List[Any]:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_distilbert_for_sequence_classification(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Optional[int]:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_distilbert_for_token_classification(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     List[Any]:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_distilbert_for_multiple_choice(*__UpperCAmelCase							)

			@slow
			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     int:
						for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE__										=   DistilBertModel.from_pretrained(__UpperCAmelCase							)
									self.assertIsNotNone(__UpperCAmelCase							)





			@slow
			@require_torch_gpu
			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]							) ->     Any:
						SCREAMING_SNAKE_CASE__				,		SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs_for_common()
						for model_class in self.all_model_classes:
									# BertForMultipleChoice behaves incorrectly in JIT environments.
									if model_class == DistilBertForMultipleChoice:
												return

									SCREAMING_SNAKE_CASE__										=   True
									SCREAMING_SNAKE_CASE__										=   model_class(config=__UpperCAmelCase							)

									SCREAMING_SNAKE_CASE__										=   self._prepare_for_class(__UpperCAmelCase     ,					__UpperCAmelCase							)
									SCREAMING_SNAKE_CASE__										=   torch.jit.trace(
									    __UpperCAmelCase     ,					(inputs_dict["""input_ids"""].to("""cpu"""							), inputs_dict["""attention_mask"""].to("""cpu"""							))							)

									with tempfile.TemporaryDirectory() as tmp:
												torch.jit.save(__UpperCAmelCase     ,					os.path.join(__UpperCAmelCase     ,					"""traced_model.pt"""							)							)
												SCREAMING_SNAKE_CASE__										=   torch.jit.load(os.path.join(__UpperCAmelCase     ,					"""traced_model.pt"""							)     ,					map_location=__UpperCAmelCase							)
												loaded(inputs_dict["""input_ids"""].to(__UpperCAmelCase							)     ,					inputs_dict["""attention_mask"""].to(__UpperCAmelCase							)							)





@require_torch
class  lowerCamelCase    (unittest.TestCase      ):

			@slow
			def        SCREAMING_SNAKE_CASE					(       self					:    int							) ->     Dict:
						SCREAMING_SNAKE_CASE__										=   DistilBertModel.from_pretrained("""distilbert-base-uncased"""							)
						SCREAMING_SNAKE_CASE__										=   torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]							)
						SCREAMING_SNAKE_CASE__										=   torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
						with torch.no_grad():
									SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase							)[0]
						SCREAMING_SNAKE_CASE__										=   torch.Size((1, 1_1, 7_6_8)							)
						self.assertEqual(output.shape     ,					__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   torch.tensor(
						    [[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]							)

						self.assertTrue(torch.allclose(output[:, 1:4, 1:4]     ,					__UpperCAmelCase     ,					atol=1e-4							)							)





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


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import MobileViTImageProcessor





class  lowerCamelCase    (unittest.TestCase      ):

			def __init__(       self					:    Tuple     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Any=7     ,					__UpperCAmelCase					:    Union[str, Any]=3     ,					__UpperCAmelCase					:    Any=1_8     ,					__UpperCAmelCase					:    Tuple=3_0     ,					__UpperCAmelCase					:    List[Any]=4_0_0     ,					__UpperCAmelCase					:    Dict=True     ,					__UpperCAmelCase					:    int=None     ,					__UpperCAmelCase					:    List[Any]=True     ,					__UpperCAmelCase					:    Any=None     ,					__UpperCAmelCase					:    Any=True     ,					) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   size if size is not None else {"""shortest_edge""": 2_0}
						SCREAMING_SNAKE_CASE__										=   crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}
						SCREAMING_SNAKE_CASE__										=   parent
						SCREAMING_SNAKE_CASE__										=   batch_size
						SCREAMING_SNAKE_CASE__										=   num_channels
						SCREAMING_SNAKE_CASE__										=   image_size
						SCREAMING_SNAKE_CASE__										=   min_resolution
						SCREAMING_SNAKE_CASE__										=   max_resolution
						SCREAMING_SNAKE_CASE__										=   do_resize
						SCREAMING_SNAKE_CASE__										=   size
						SCREAMING_SNAKE_CASE__										=   do_center_crop
						SCREAMING_SNAKE_CASE__										=   crop_size
						SCREAMING_SNAKE_CASE__										=   do_flip_channel_order





			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Any:
						return {
						    "do_resize": self.do_resize,
						    "size": self.size,
						    "do_center_crop": self.do_center_crop,
						    "crop_size": self.crop_size,
						    "do_flip_channel_order": self.do_flip_channel_order,
						}





@require_torch
@require_vision
class  lowerCamelCase    (A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		Tuple       		=				MobileViTImageProcessor if is_vision_available() else None

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Any:
						SCREAMING_SNAKE_CASE__										=   MobileViTImageProcessingTester(self							)

			@property
			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     int:
						return self.image_processor_tester.prepare_image_processor_dict()

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Optional[Any]:
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_resize"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""size"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_center_crop"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""center_crop"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_flip_channel_order"""							)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     List[str]:
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class.from_dict(self.image_processor_dict							)
						self.assertEqual(image_processor.size     ,					{"""shortest_edge""": 2_0}							)
						self.assertEqual(image_processor.crop_size     ,					{"""height""": 1_8, """width""": 1_8}							)

						SCREAMING_SNAKE_CASE__										=   self.image_processing_class.from_dict(self.image_processor_dict     ,					size=4_2     ,					crop_size=8_4							)
						self.assertEqual(image_processor.size     ,					{"""shortest_edge""": 4_2}							)
						self.assertEqual(image_processor.crop_size     ,					{"""height""": 8_4, """width""": 8_4}							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Dict:
						pass

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     List[str]:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random PIL images
						SCREAMING_SNAKE_CASE__										=   prepare_image_inputs(self.image_processor_tester     ,					equal_resolution=__UpperCAmelCase							)
						for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase     ,					Image.Image							)

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

						# Test batched
						SCREAMING_SNAKE_CASE__										=   image_processing(__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					:    List[Any]							) ->     Optional[int]:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random numpy tensors
						SCREAMING_SNAKE_CASE__										=   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
						SCREAMING_SNAKE_CASE__										=   image_processing(image_inputs[0]     ,					return_tensors="""pt"""							).pixel_values
						self.assertEqual(
						    encoded_images.shape     ,					(
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["""height"""],
						        self.image_processor_tester.crop_size["""width"""],
						    )     ,					)

						# Test batched
						SCREAMING_SNAKE_CASE__										=   image_processing(__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					:    List[str]							) ->     str:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random PyTorch tensors
						SCREAMING_SNAKE_CASE__										=   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
						SCREAMING_SNAKE_CASE__										=   image_processing(image_inputs[0]     ,					return_tensors="""pt"""							).pixel_values
						self.assertEqual(
						    encoded_images.shape     ,					(
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["""height"""],
						        self.image_processor_tester.crop_size["""width"""],
						    )     ,					)

						# Test batched
						SCREAMING_SNAKE_CASE__										=   image_processing(__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"""],
						    )     ,					)


