






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 DeiTImageProcessor





class   SCREAMING_SNAKE_CASE (       unittest.TestCase    ):





							"""simple docstring"""

							def __init__(     self:      Union[str, Any]						,   __A:      int						,   __A:      Any=7						,   __A:      List[Any]=3						,   __A:      List[Any]=18						,   __A:      Optional[Any]=30						,   __A:      Optional[Any]=4_00						,   __A:      Any=True						,   __A:      int=None						,   __A:      Union[str, Any]=True						,   __A:      List[Any]=None						,   __A:      List[str]=True						,   __A:      List[str]=[0.5, 0.5, 0.5]						,   __A:      int=[0.5, 0.5, 0.5]						,   )			-> str:
												_A									=       size if size is not None else {'''height''': 20, '''width''': 20}
												_A									=       crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

												_A									=       parent
												_A									=       batch_size
												_A									=       num_channels
												_A									=       image_size
												_A									=       min_resolution
												_A									=       max_resolution
												_A									=       do_resize
												_A									=       size
												_A									=       do_center_crop
												_A									=       crop_size
												_A									=       do_normalize
												_A									=       image_mean
												_A									=       image_std



							def 					__A       (     self:      Union[str, Any]      )			-> Union[str, Any]:
												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,
												}





@require_torch
@require_vision
class   SCREAMING_SNAKE_CASE (       snake_case     ,		unittest.TestCase    ):





							"""simple docstring"""

							A_       =    DeiTImageProcessor if is_vision_available() else None
							A_       =    True

							def 					__A       (     self:      List[Any]      )			-> Optional[int]:
												_A									=       DeiTImageProcessingTester(self      )

							@property
							def 					__A       (     self:      Union[str, Any]      )			-> Optional[int]:
												return self.image_processor_tester.prepare_image_processor_dict()

							def 					__A       (     self:      Optional[Any]      )			-> Any:
												_A									=       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'''      )      )

							def 					__A       (     self:      List[str]      )			-> int:
												_A									=       self.image_processing_class.from_dict(self.image_processor_dict      )
												self.assertEqual(image_processor.size						,   {'''height''': 20, '''width''': 20}      )
												self.assertEqual(image_processor.crop_size						,   {'''height''': 18, '''width''': 18}      )

												_A									=       self.image_processing_class.from_dict(self.image_processor_dict						,   size=42						,   crop_size=84      )
												self.assertEqual(image_processor.size						,   {'''height''': 42, '''width''': 42}      )
												self.assertEqual(image_processor.crop_size						,   {'''height''': 84, '''width''': 84}      )

							def 					__A       (     self:      str      )			-> Dict:
												pass

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

												# Test not batched input
												_A									=       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
												_A									=       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:      Any      )			-> int:
												# Initialize image_processing
												_A									=       self.image_processing_class(**self.image_processor_dict      )
												# create random numpy tensors
												_A									=       prepare_image_inputs(self.image_processor_tester						,   equal_resolution=__A						,   numpify=__A      )
												for image in image_inputs:
																	self.assertIsInstance(__A						,   np.ndarray      )

												# Test not batched input
												_A									=       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
												_A									=       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:      Any      )			-> Optional[Any]:
												# Initialize image_processing
												_A									=       self.image_processing_class(**self.image_processor_dict      )
												# create random PyTorch tensors
												_A									=       prepare_image_inputs(self.image_processor_tester						,   equal_resolution=__A						,   torchify=__A      )
												for image in image_inputs:
																	self.assertIsInstance(__A						,   torch.Tensor      )

												# Test not batched input
												_A									=       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
												_A									=       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'''],
												    )						,   )










'''simple docstring'''



import torch

from transformers import PreTrainedModel

from .custom_configuration import CustomConfig, NoSuperInitConfig






class 							__lowercase				(					lowerCAmelCase__  ):







	'''simple docstring'''

	a			: Union[str, Any]      =				CustomConfig


	def __init__(self   ,_lowerCamelCase       )							->							Tuple:







				'''simple docstring'''





				super().__init__(_lowerCamelCase       )
				__lowercase   =							torch.nn.Linear(config.hidden_size   ,config.hidden_size       )


	def   _UpperCAmelCase   (self   ,_lowerCamelCase       )							->							List[str]:







				'''simple docstring'''





				return self.linear(_lowerCamelCase       )


	def   _UpperCAmelCase   (self   ,_lowerCamelCase       )							->							List[Any]:







				'''simple docstring'''





				pass






class 							__lowercase				(					lowerCAmelCase__  ):







	'''simple docstring'''

	a			: Dict      =				NoSuperInitConfig


	def __init__(self   ,_lowerCamelCase       )							->							str:







				'''simple docstring'''





				super().__init__(_lowerCamelCase       )
				__lowercase   =							torch.nn.Linear(config.attribute   ,config.attribute       )


	def   _UpperCAmelCase   (self   ,_lowerCamelCase       )							->							List[str]:







				'''simple docstring'''





				return self.linear(_lowerCamelCase       )


	def   _UpperCAmelCase   (self   ,_lowerCamelCase       )							->							Tuple:







				'''simple docstring'''





				pass





