





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 PoolFormerImageProcessor
class SCREAMING_SNAKE_CASE_						(					unittest.TestCase					):






						def __init__(      self      :      Any		,   _A      :      Union[str, Any]		,   _A      :      Tuple=7		,   _A      :      Optional[int]=3		,   _A      :      Dict=30		,   _A      :      str=400		,   _A      :      List[Any]=True		,   _A      :      Optional[int]=None		,   _A      :      int=0.9		,   _A      :      Dict=None		,   _A      :      Union[str, Any]=True		,   _A      :      Tuple=[0.5, 0.5, 0.5]		,   _A      :      Optional[Any]=[0.5, 0.5, 0.5]		,   )							->    Optional[Any]:







							"""simple docstring"""


							snake_case_		:			Optional[int]											=	size if size is not None else {'shortest_edge': 30}
							snake_case_		:			Dict											=	crop_size if crop_size is not None else {'height': 30, 'width': 30}
							snake_case_		:			Union[str, Any]											=	parent
							snake_case_		:			Dict											=	batch_size
							snake_case_		:			Optional[int]											=	num_channels
							snake_case_		:			Optional[int]											=	min_resolution
							snake_case_		:			Tuple											=	max_resolution
							snake_case_		:			str											=	do_resize_and_center_crop
							snake_case_		:			Union[str, Any]											=	size
							snake_case_		:			str											=	crop_pct
							snake_case_		:			Dict											=	crop_size
							snake_case_		:			List[str]											=	do_normalize
							snake_case_		:			List[str]											=	image_mean
							snake_case_		:			Dict											=	image_std






						def UpperCAmelCase_				(      self      :      Tuple	)							->    Tuple:







							"""simple docstring"""


							return {
							    "size": self.size,
							    "do_resize_and_center_crop": self.do_resize_and_center_crop,
							    "crop_pct": self.crop_pct,
							    "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					):
						__magic_name__:			List[str]       =       PoolFormerImageProcessor if is_vision_available() else None






						def UpperCAmelCase_				(      self      :      str	)							->    Any:







							"""simple docstring"""


							snake_case_		:			List[str]											=	PoolFormerImageProcessingTester(self	)






						@property
						def UpperCAmelCase_				(      self      :      Dict	)							->    List[str]:







							"""simple docstring"""


							return self.image_processor_tester.prepare_image_processor_dict()






						def UpperCAmelCase_				(      self      :      int	)							->    str:







							"""simple docstring"""


							snake_case_		:			Optional[Any]											=	self.image_processing_class(**self.image_processor_dict	)
							self.assertTrue(hasattr(_A		,   'do_resize_and_center_crop'	)	)
							self.assertTrue(hasattr(_A		,   'size'	)	)
							self.assertTrue(hasattr(_A		,   'crop_pct'	)	)
							self.assertTrue(hasattr(_A		,   'do_normalize'	)	)
							self.assertTrue(hasattr(_A		,   'image_mean'	)	)
							self.assertTrue(hasattr(_A		,   'image_std'	)	)






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







							"""simple docstring"""


							snake_case_		:			List[str]											=	self.image_processing_class.from_dict(self.image_processor_dict	)
							self.assertEqual(image_processor.size		,   {'shortest_edge': 30}	)
							self.assertEqual(image_processor.crop_size		,   {'height': 30, 'width': 30}	)

							snake_case_		:			List[Any]											=	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 UpperCAmelCase_				(      self      :      Any	)							->    Dict:







							"""simple docstring"""


							pass






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







							"""simple docstring"""


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

							# Test not batched input
							snake_case_		:			Optional[Any]											=	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
							snake_case_		:			Any											=	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 UpperCAmelCase_				(      self      :      List[str]	)							->    List[str]:







							"""simple docstring"""


							snake_case_		:			Dict											=	self.image_processing_class(**self.image_processor_dict	)
							# create random numpy tensors
							snake_case_		:			Optional[Any]											=	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
							snake_case_		:			Dict											=	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
							snake_case_		:			Optional[int]											=	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 UpperCAmelCase_				(      self      :      str	)							->    Any:







							"""simple docstring"""


							snake_case_		:			int											=	self.image_processing_class(**self.image_processor_dict	)
							# create random PyTorch tensors
							snake_case_		:			str											=	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
							snake_case_		:			Tuple											=	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
							snake_case_		:			Tuple											=	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'],
							    )		,   )








from ....utils import logging


_SCREAMING_SNAKE_CASE      	=		logging.get_logger(__name__)
class SCREAMING_SNAKE_CASE_						(					snake_case_					):






						def __init__(      self      :      str		,   _A      :      List[Any]		,   _A      :      List[Any]=None		,   _A      :      str=2048	)							->    Optional[int]:







							"""simple docstring"""


							snake_case_		:			Tuple											=	config.__dict__
							snake_case_		:			List[str]											=	modal_hidden_size
							if num_labels:
								snake_case_		:			int											=	num_labels

