


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 							lowercase  (						unittest.TestCase			):







     def __init__(						self :						Optional[Any]   ,   _lowercase :						Any   ,   _lowercase :						List[str]=7   ,   _lowercase :						Tuple=3   ,   _lowercase :						List[str]=30   ,   _lowercase :						Optional[Any]=4_00   ,   _lowercase :						Any=True   ,   _lowercase :						Union[str, Any]=None   ,   _lowercase :						List[Any]=0.9   ,   _lowercase :						Optional[Any]=None   ,   _lowercase :						Optional[Any]=True   ,   _lowercase :						Optional[Any]=[0.5, 0.5, 0.5]   ,   _lowercase :						int=[0.5, 0.5, 0.5]   ,   ):
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		size if size is not None else {'''shortest_edge''': 30}
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		crop_size if crop_size is not None else {'''height''': 30, '''width''': 30}
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		parent
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		batch_size
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		num_channels
           SCREAMING_SNAKE_CASE__       :  Dict						     =		min_resolution
           SCREAMING_SNAKE_CASE__       :  str						     =		max_resolution
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		do_resize_and_center_crop
           SCREAMING_SNAKE_CASE__       :  str						     =		size
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		crop_pct
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		crop_size
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		do_normalize
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		image_mean
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		image_std







     def 							lowercase__       (						self :						Optional[Any]      ):
           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 							lowercase  (						_UpperCAmelCase    ,       unittest.TestCase			):
     lowerCamelCase			:			Dict      = PoolFormerImageProcessor if is_vision_available() else None







     def 							lowercase__       (						self :						Optional[Any]      ):
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		PoolFormerImageProcessingTester(self      )







     @property
     def 							lowercase__       (						self :						Union[str, Any]      ):
           return self.image_processor_tester.prepare_image_processor_dict()







     def 							lowercase__       (						self :						str      ):
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		self.image_processing_class(**self.image_processor_dict      )
           self.assertTrue(hasattr(_lowercase   ,   '''do_resize_and_center_crop'''      )      )
           self.assertTrue(hasattr(_lowercase   ,   '''size'''      )      )
           self.assertTrue(hasattr(_lowercase   ,   '''crop_pct'''      )      )
           self.assertTrue(hasattr(_lowercase   ,   '''do_normalize'''      )      )
           self.assertTrue(hasattr(_lowercase   ,   '''image_mean'''      )      )
           self.assertTrue(hasattr(_lowercase   ,   '''image_std'''      )      )







     def 							lowercase__       (						self :						Dict      ):
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		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}      )

           SCREAMING_SNAKE_CASE__       :  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 							lowercase__       (						self :						Optional[int]      ):
           pass







     def 							lowercase__       (						self :						Dict      ):
           # Initialize image_processing
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		self.image_processing_class(**self.image_processor_dict      )
           # create random PIL images
           SCREAMING_SNAKE_CASE__       :  int						     =		prepare_image_inputs(self.image_processor_tester   ,   equal_resolution=_lowercase      )
           for image in image_inputs:
                 self.assertIsInstance(_lowercase   ,   Image.Image      )

           # Test not batched input
           SCREAMING_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
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		image_processing(_lowercase   ,   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 							lowercase__       (						self :						Tuple      ):
           # Initialize image_processing
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		self.image_processing_class(**self.image_processor_dict      )
           # create random numpy tensors
           SCREAMING_SNAKE_CASE__       :  Any						     =		prepare_image_inputs(self.image_processor_tester   ,   equal_resolution=_lowercase   ,   numpify=_lowercase      )
           for image in image_inputs:
                 self.assertIsInstance(_lowercase   ,   np.ndarray      )

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

           # Test not batched input
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		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__       :  Union[str, Any]						     =		image_processing(_lowercase   ,   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'''

def 					__UpperCamelCase				(						lowercase__    :	list[int]			):






     '''simple docstring'''





     if not nums:  # Makes sure that the list is not empty
          raise ValueError('List is empty'			)

     __lowercase      		=sum(lowercase__			) / len(lowercase__			)  # Calculate the average
     return sum(abs(x - average			) for x in nums			) / len(lowercase__			)


if __name__ == "__main__":
       import doctest

       doctest.testmod()


