





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):

      """simple docstring"""


      def __init__(						self:       str     ,  __lowerCamelCase:       Dict     ,  __lowerCamelCase:       Optional[int]=7     ,  __lowerCamelCase:       Any=3     ,  __lowerCamelCase:       Tuple=30     ,  __lowerCamelCase:       Any=400     ,  __lowerCamelCase:       Union[str, Any]=True     ,  __lowerCamelCase:       Optional[int]=None     ,  __lowerCamelCase:       str=0.9     ,  __lowerCamelCase:       Union[str, Any]=None     ,  __lowerCamelCase:       str=True     ,  __lowerCamelCase:       str=[0.5, 0.5, 0.5]     ,  __lowerCamelCase:       int=[0.5, 0.5, 0.5]     ,  ):
          '''simple docstring'''


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






      def        UpperCAmelCase_    (						self:       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  (  UpperCamelCase__		,       unittest.TestCase):

      """simple docstring"""


      UpperCamelCase__   						=    PoolFormerImageProcessor if is_vision_available() else None






      def        UpperCAmelCase_    (						self:       Any ):
          '''simple docstring'''


          UpperCamelCase__:     List[str]     							=			PoolFormerImageProcessingTester(self )






      @property
      def        UpperCAmelCase_    (						self:       Dict ):
          '''simple docstring'''


          return self.image_processor_tester.prepare_image_processor_dict()






      def        UpperCAmelCase_    (						self:       Optional[int] ):
          '''simple docstring'''


          UpperCamelCase__:     List[str]     							=			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        UpperCAmelCase_    (						self:       List[str] ):
          '''simple docstring'''


          UpperCamelCase__:     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} )

          UpperCamelCase__:     int     							=			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:       Optional[int] ):
          '''simple docstring'''


          pass






      def        UpperCAmelCase_    (						self:       List[Any] ):
          '''simple docstring'''


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

          # Test not batched input
          UpperCamelCase__:     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
          UpperCamelCase__:     Any     							=			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        UpperCAmelCase_    (						self:       Tuple ):
          '''simple docstring'''


          UpperCamelCase__:     int     							=			self.image_processing_class(**self.image_processor_dict )
          # create random numpy tensors
          UpperCamelCase__:     int     							=			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
          UpperCamelCase__:     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
          UpperCamelCase__:     Optional[Any]     							=			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        UpperCAmelCase_    (						self:       Union[str, Any] ):
          '''simple docstring'''


          UpperCamelCase__:     int     							=			self.image_processing_class(**self.image_processor_dict )
          # create random PyTorch tensors
          UpperCamelCase__:     int     							=			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
          UpperCamelCase__:     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
          UpperCamelCase__:     Any     							=			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"""
import warnings

from ...utils import logging
from .image_processing_donut import DonutImageProcessor


_lowerCAmelCase    :Optional[int]     =					logging.get_logger(__name__)
class 							_UpperCAmelCase							( a      ):





     '''simple docstring'''



     def __init__(					self       ,	*A       ,	**A		)							->					None:
         warnings.warn(
             '''The class DonutFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please'''
             ''' use DonutImageProcessor instead.'''       ,	A       ,	)
         super().__init__(*A       ,	**A		)


