
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 EfficientNetImageProcessor






class     SCREAMING_SNAKE_CASE__      (							unittest.TestCase      ):

							"""simple docstring"""






							def __init__(					self       ,		SCREAMING_SNAKE_CASE_       ,		SCREAMING_SNAKE_CASE_=13       ,		SCREAMING_SNAKE_CASE_=3       ,		SCREAMING_SNAKE_CASE_=18       ,		SCREAMING_SNAKE_CASE_=30       ,		SCREAMING_SNAKE_CASE_=400       ,		SCREAMING_SNAKE_CASE_=True       ,		SCREAMING_SNAKE_CASE_=None       ,		SCREAMING_SNAKE_CASE_=True       ,		SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5]       ,		SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5]       ,		)->				Optional[Any]:





													'''simple docstring'''






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



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





													'''simple docstring'''






													return {
													    "image_mean": self.image_mean,
													    "image_std": self.image_std,
													    "do_normalize": self.do_normalize,
													    "do_resize": self.do_resize,
													    "size": self.size,
													}






@require_torch
@require_vision
class     SCREAMING_SNAKE_CASE__      (							SCREAMING_SNAKE_CASE_				,						unittest.TestCase      ):

							"""simple docstring"""






							_snake_case       						=					EfficientNetImageProcessor if is_vision_available() else None



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





													'''simple docstring'''






													__UpperCamelCase       					=     EfficientNetImageProcessorTester(self     )



							@property
							def       A__						(					self     )->				str:





													'''simple docstring'''






													return self.image_processor_tester.prepare_image_processor_dict()



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





													'''simple docstring'''






													__UpperCamelCase       					=     self.image_processing_class(**self.image_processor_dict     )
													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,		'''image_mean'''     )     )
													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,		'''image_std'''     )     )
													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,		'''do_normalize'''     )     )
													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,		'''do_resize'''     )     )
													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,		'''size'''     )     )



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





													'''simple docstring'''






													__UpperCamelCase       					=     self.image_processing_class.from_dict(self.image_processor_dict     )
													self.assertEqual(image_processor.size       ,		{'''height''': 18, '''width''': 18}     )

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



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





													'''simple docstring'''






													__UpperCamelCase       					=     self.image_processing_class(**self.image_processor_dict     )
													# create random PIL images
													__UpperCamelCase       					=     prepare_image_inputs(self.image_processor_tester       ,		equal_resolution=SCREAMING_SNAKE_CASE_     )
													for image in image_inputs:
																			self.assertIsInstance(SCREAMING_SNAKE_CASE_       ,		Image.Image     )

													# Test not batched input
													__UpperCamelCase       					=     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.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )       ,		)

													# Test batched
													__UpperCamelCase       					=     image_processing(SCREAMING_SNAKE_CASE_       ,		return_tensors='''pt'''     ).pixel_values
													self.assertEqual(
													    encoded_images.shape       ,		(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )       ,		)



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





													'''simple docstring'''






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

													# Test not batched input
													__UpperCamelCase       					=     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.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )       ,		)

													# Test batched
													__UpperCamelCase       					=     image_processing(SCREAMING_SNAKE_CASE_       ,		return_tensors='''pt'''     ).pixel_values
													self.assertEqual(
													    encoded_images.shape       ,		(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )       ,		)



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





													'''simple docstring'''






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

													# Test not batched input
													__UpperCamelCase       					=     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.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )       ,		)

													# Test batched
													__UpperCamelCase       					=     image_processing(SCREAMING_SNAKE_CASE_       ,		return_tensors='''pt'''     ).pixel_values
													self.assertEqual(
													    encoded_images.shape       ,		(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )       ,		)






import torch

from transformers import PreTrainedModel

from .custom_configuration import CustomConfig, NoSuperInitConfig






class     SCREAMING_SNAKE_CASE__      (							SCREAMING_SNAKE_CASE_      ):

							"""simple docstring"""






							_snake_case       						=					CustomConfig



							def __init__(					self       ,		SCREAMING_SNAKE_CASE_     )->				Tuple:





													'''simple docstring'''






													super().__init__(SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     torch.nn.Linear(config.hidden_size       ,		config.hidden_size     )



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





													'''simple docstring'''






													return self.linear(SCREAMING_SNAKE_CASE_     )



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_     )->				Any:





													'''simple docstring'''






													pass






class     SCREAMING_SNAKE_CASE__      (							SCREAMING_SNAKE_CASE_      ):

							"""simple docstring"""






							_snake_case       						=					NoSuperInitConfig



							def __init__(					self       ,		SCREAMING_SNAKE_CASE_     )->				Tuple:





													'''simple docstring'''






													super().__init__(SCREAMING_SNAKE_CASE_     )
													__UpperCamelCase       					=     torch.nn.Linear(config.attribute       ,		config.attribute     )



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





													'''simple docstring'''






													return self.linear(SCREAMING_SNAKE_CASE_     )



							def       A__						(					self       ,		SCREAMING_SNAKE_CASE_     )->				Union[str, Any]:





													'''simple docstring'''






													pass




