






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


class 	__UpperCAmelCase		(				unittest.TestCase	):


	'''simple docstring'''





	def __init__(     self      ,      _A      ,      _A=7      ,      _A=3      ,      _A=3_0      ,      _A=4_0_0      ,      _A=True      ,      _A=None      ,      _A=0.9      ,      _A=None      ,      _A=True      ,      _A=[0.5, 0.5, 0.5]      ,      _A=[0.5, 0.5, 0.5]      ,      ):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=size if size is not None else {'''shortest_edge''': 3_0}
		_SCREAMING_SNAKE_CASE						=crop_size if crop_size is not None else {'''height''': 3_0, '''width''': 3_0}
		_SCREAMING_SNAKE_CASE						=parent
		_SCREAMING_SNAKE_CASE						=batch_size
		_SCREAMING_SNAKE_CASE						=num_channels
		_SCREAMING_SNAKE_CASE						=min_resolution
		_SCREAMING_SNAKE_CASE						=max_resolution
		_SCREAMING_SNAKE_CASE						=do_resize_and_center_crop
		_SCREAMING_SNAKE_CASE						=size
		_SCREAMING_SNAKE_CASE						=crop_pct
		_SCREAMING_SNAKE_CASE						=crop_size
		_SCREAMING_SNAKE_CASE						=do_normalize
		_SCREAMING_SNAKE_CASE						=image_mean
		_SCREAMING_SNAKE_CASE						=image_std







	def 				UpperCamelCase_  (     self					):



		'''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 	__UpperCAmelCase		(				_lowerCAmelCase,  unittest.TestCase	):


	'''simple docstring'''





	lowercase		:	List[Any]							     =				PoolFormerImageProcessor if is_vision_available() else None


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=PoolFormerImageProcessingTester(self					)


	@property
	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		return self.image_processor_tester.prepare_image_processor_dict()


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=self.image_processing_class(**self.image_processor_dict					)
		self.assertTrue(hasattr(UpperCAmelCase_      ,      '''do_resize_and_center_crop'''					)					)
		self.assertTrue(hasattr(UpperCAmelCase_      ,      '''size'''					)					)
		self.assertTrue(hasattr(UpperCAmelCase_      ,      '''crop_pct'''					)					)
		self.assertTrue(hasattr(UpperCAmelCase_      ,      '''do_normalize'''					)					)
		self.assertTrue(hasattr(UpperCAmelCase_      ,      '''image_mean'''					)					)
		self.assertTrue(hasattr(UpperCAmelCase_      ,      '''image_std'''					)					)


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=self.image_processing_class.from_dict(self.image_processor_dict					)
		self.assertEqual(image_processor.size      ,      {'''shortest_edge''': 3_0}					)
		self.assertEqual(image_processor.crop_size      ,      {'''height''': 3_0, '''width''': 3_0}					)

		_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 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		pass


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_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 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_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 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_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'''],
		    )      ,      )






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



class 	__a	(   unittest.TestCase						):






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







              """simple docstring"""
              UpperCamelCase       			=		size if size is not None else {"shortest_edge": 30}
              UpperCamelCase       			=		crop_size if crop_size is not None else {"height": 30, "width": 30}
              UpperCamelCase       			=		parent
              UpperCamelCase       			=		batch_size
              UpperCamelCase       			=		num_channels
              UpperCamelCase       			=		min_resolution
              UpperCamelCase       			=		max_resolution
              UpperCamelCase       			=		do_resize_and_center_crop
              UpperCamelCase       			=		size
              UpperCamelCase       			=		crop_pct
              UpperCamelCase       			=		crop_size
              UpperCamelCase       			=		do_normalize
              UpperCamelCase       			=		image_mean
              UpperCamelCase       			=		image_std






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







              """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 	__a	(   _lowerCAmelCase     ,  unittest.TestCase						):
       UpperCamelCase_		:       List[Any]				=      PoolFormerImageProcessor if is_vision_available() else None






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







              """simple docstring"""
              UpperCamelCase       			=		PoolFormerImageProcessingTester(self      )






       @property
       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[Any]      )->	Optional[Any]:







              """simple docstring"""
              return self.image_processor_tester.prepare_image_processor_dict()






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Dict      )->	Optional[int]:







              """simple docstring"""
              UpperCamelCase       			=		self.image_processing_class(**self.image_processor_dict      )
              self.assertTrue(hasattr(UpperCAmelCase_							,   "do_resize_and_center_crop"      )      )
              self.assertTrue(hasattr(UpperCAmelCase_							,   "size"      )      )
              self.assertTrue(hasattr(UpperCAmelCase_							,   "crop_pct"      )      )
              self.assertTrue(hasattr(UpperCAmelCase_							,   "do_normalize"      )      )
              self.assertTrue(hasattr(UpperCAmelCase_							,   "image_mean"      )      )
              self.assertTrue(hasattr(UpperCAmelCase_							,   "image_std"      )      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				int      )->	List[Any]:







              """simple docstring"""
              UpperCamelCase       			=		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}      )

              UpperCamelCase       			=		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 						_SCREAMING_SNAKE_CASE							(	self			:				Union[str, Any]      )->	Any:







              """simple docstring"""
              pass






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







              """simple docstring"""
              # Initialize image_processing
              UpperCamelCase       			=		self.image_processing_class(**self.image_processor_dict      )
              # create random PIL images
              UpperCamelCase       			=		prepare_image_inputs(self.image_processor_tester							,   equal_resolution=UpperCAmelCase_      )
              for image in image_inputs:
                     self.assertIsInstance(UpperCAmelCase_							,   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.crop_size["height"],
                      self.image_processor_tester.crop_size["width"],
                  )							,   )

              # Test batched
              UpperCamelCase       			=		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			:				Optional[int]      )->	List[str]:







              """simple docstring"""
              # Initialize image_processing
              UpperCamelCase       			=		self.image_processing_class(**self.image_processor_dict      )
              # create random numpy tensors
              UpperCamelCase       			=		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
              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.crop_size["height"],
                      self.image_processor_tester.crop_size["width"],
                  )							,   )

              # Test batched
              UpperCamelCase       			=		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			:				str      )->	str:







              """simple docstring"""
              # Initialize image_processing
              UpperCamelCase       			=		self.image_processing_class(**self.image_processor_dict      )
              # create random PyTorch tensors
              UpperCamelCase       			=		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
              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.crop_size["height"],
                      self.image_processor_tester.crop_size["width"],
                  )							,   )

              # Test batched
              UpperCamelCase       			=		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"],
                  )							,   )





