"""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		,       __lowerCAmelCase		,       __lowerCAmelCase=7		,       __lowerCAmelCase=3		,       __lowerCAmelCase=30		,       __lowerCAmelCase=400		,       __lowerCAmelCase=True		,       __lowerCAmelCase=None		,       __lowerCAmelCase=0.9		,       __lowerCAmelCase=None		,       __lowerCAmelCase=True		,       __lowerCAmelCase=[0.5, 0.5, 0.5]		,       __lowerCAmelCase=[0.5, 0.5, 0.5]		,       ):







            """simple docstring"""



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







      def 				A__       (						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  _A						(       lowerCAmelCase  ,    unittest.TestCase	):
      snake_case__			:   List[str]							  =	PoolFormerImageProcessor if is_vision_available() else None

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	PoolFormerImageProcessingTester(self						)

      @property
      def 				A__       (						self						):







            """simple docstring"""



            return self.image_processor_tester.prepare_image_processor_dict()

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.image_processing_class(**self.image_processor_dict						)
            self.assertTrue(hasattr(__lowerCAmelCase		,       """do_resize_and_center_crop"""						)						)
            self.assertTrue(hasattr(__lowerCAmelCase		,       """size"""						)						)
            self.assertTrue(hasattr(__lowerCAmelCase		,       """crop_pct"""						)						)
            self.assertTrue(hasattr(__lowerCAmelCase		,       """do_normalize"""						)						)
            self.assertTrue(hasattr(__lowerCAmelCase		,       """image_mean"""						)						)
            self.assertTrue(hasattr(__lowerCAmelCase		,       """image_std"""						)						)

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	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}						)

            lowercase														=	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 				A__       (						self						):







            """simple docstring"""



            pass

      def 				A__       (						self						):







            """simple docstring"""



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

            # Test not batched input
            lowercase														=	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
            lowercase														=	image_processing(__lowerCAmelCase		,       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 				A__       (						self						):







            """simple docstring"""



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

            # Test not batched input
            lowercase														=	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
            lowercase														=	image_processing(__lowerCAmelCase		,       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 				A__       (						self						):







            """simple docstring"""



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

            # Test not batched input
            lowercase														=	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
            lowercase														=	image_processing(__lowerCAmelCase		,       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"""






from ..utils import DummyObject, requires_backends





class  _A						(       metaclass=lowerCAmelCase	):
      snake_case__			:   List[str]							  =	['onnx']

      def __init__(						self		,       *__lowerCAmelCase		,       **__lowerCAmelCase						):







            """simple docstring"""



            requires_backends(self		,       ["""onnx"""]						)

      @classmethod
      def 				A__       (						cls		,       *__lowerCAmelCase		,       **__lowerCAmelCase						):







            """simple docstring"""



            requires_backends(cls		,       ["""onnx"""]						)







      @classmethod
      def 				A__       (						cls		,       *__lowerCAmelCase		,       **__lowerCAmelCase						):







            """simple docstring"""



            requires_backends(cls		,       ["""onnx"""]						)



