






"""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 ViTImageProcessor





class       snake_case_       (    unittest.TestCase       ):


	def __init__(      self  ,					__a  ,					__a=13  ,					__a=3  ,					__a=224  ,					__a=30  ,					__a=400  ,					__a=True  ,					__a=None  ,					__a=True  ,					__a=[0.5, 0.5, 0.5]  ,					__a=[0.5, 0.5, 0.5]  ,					):


					"""simple docstring"""

					A__							 =       size if 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_normalize
					A__							 =       image_mean
					A__							 =       image_std






	def       _UpperCAmelCase						(      self						):


					"""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       snake_case_       (    lowerCamelCase__    ,							unittest.TestCase       ):
	SCREAMING_SNAKE_CASE_:							List[str]   			=					ViTImageProcessor if is_vision_available() else None


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       EfficientFormerImageProcessorTester(self						)


	@property
	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					return self.image_proc_tester.prepare_image_processor_dict()


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

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


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					pass


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.image_processing_class(**self.image_processor_dict						)
					# create random PIL images
					A__							 =       prepare_image_inputs(self.image_proc_tester  ,					equal_resolution=__lowerCamelCase						)
					for image in image_inputs:
									self.assertIsInstance(__lowerCamelCase  ,					Image.Image						)

					# Test not batched input
					A__							 =       image_processor(image_inputs[0]  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        1,
					        self.image_proc_tester.num_channels,
					        self.image_proc_tester.size['height'],
					        self.image_proc_tester.size['width'],
					    )  ,					)

					# Test batched
					A__							 =       image_processor(__lowerCamelCase  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        self.image_proc_tester.batch_size,
					        self.image_proc_tester.num_channels,
					        self.image_proc_tester.size['height'],
					        self.image_proc_tester.size['width'],
					    )  ,					)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

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

					# Test not batched input
					A__							 =       image_processor(image_inputs[0]  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        1,
					        self.image_proc_tester.num_channels,
					        self.image_proc_tester.size['height'],
					        self.image_proc_tester.size['width'],
					    )  ,					)

					# Test batched
					A__							 =       image_processor(__lowerCamelCase  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        self.image_proc_tester.batch_size,
					        self.image_proc_tester.num_channels,
					        self.image_proc_tester.size['height'],
					        self.image_proc_tester.size['width'],
					    )  ,					)






	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

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

					# Test not batched input
					A__							 =       image_processor(image_inputs[0]  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        1,
					        self.image_proc_tester.num_channels,
					        self.image_proc_tester.size['height'],
					        self.image_proc_tester.size['width'],
					    )  ,					)

					# Test batched
					A__							 =       image_processor(__lowerCamelCase  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        self.image_proc_tester.batch_size,
					        self.image_proc_tester.num_channels,
					        self.image_proc_tester.size['height'],
					        self.image_proc_tester.size['width'],
					    )  ,					)










"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE						:						Any					   =       logging.get_logger(__name__)





class       snake_case_       (    _lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					"""timm_backbone"""


	def __init__(      self  ,					__a=None  ,					__a=3  ,					__a=True  ,					__a=True  ,					__a=None  ,					**__a  ,					):


					"""simple docstring"""

					super().__init__(**__a						)
					A__							 =       backbone
					A__							 =       num_channels
					A__							 =       features_only
					A__							 =       use_pretrained_backbone
					A__							 =       True
					A__							 =       out_indices if out_indices is not None else (-1,)


