



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



   def __init__(       self    :	Union[str, Any]							,       __lowerCamelCase    :	Union[str, Any]							,       __lowerCamelCase    :	Optional[Any]=7							,       __lowerCamelCase    :	Tuple=3							,       __lowerCamelCase    :	int=3_0							,       __lowerCamelCase    :	Union[str, Any]=4_0_0							,       __lowerCamelCase    :	List[Any]=True							,       __lowerCamelCase    :	List[Any]=None							,       __lowerCamelCase    :	Tuple=0.9							,       __lowerCamelCase    :	List[Any]=None							,       __lowerCamelCase    :	Optional[int]=True							,       __lowerCamelCase    :	str=[0.5, 0.5, 0.5]							,       __lowerCamelCase    :	Union[str, Any]=[0.5, 0.5, 0.5]							,       ):



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





   def    __UpperCAmelCase    (       self    :	Optional[int]				):



     """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    (	__SCREAMING_SNAKE_CASE,unittest.TestCase  ):
   A__		:	Optional[Any]           =  PoolFormerImageProcessor if is_vision_available() else None



   def    __UpperCAmelCase    (       self    :	Optional[Any]				):



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



   @property
   def    __UpperCAmelCase    (       self    :	Union[str, Any]				):



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



   def    __UpperCAmelCase    (       self    :	List[str]				):



     """simple docstring"""
     _snake_case   	=      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[Any]				):



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

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



     """simple docstring"""
     pass



   def    __UpperCAmelCase    (       self    :	Tuple				):



     """simple docstring"""
     # Initialize image_processing
     _snake_case   	=      self.image_processing_class(**self.image_processor_dict				)
     # create random PIL images
     _snake_case   	=      prepare_image_inputs(self.image_processor_tester							,       equal_resolution=__lowerCamelCase				)
     for image in image_inputs:
       self.assertIsInstance(__lowerCamelCase							,       Image.Image				)

     # Test not batched input
     _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
     _snake_case   	=      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"""
     # Initialize image_processing
     _snake_case   	=      self.image_processing_class(**self.image_processor_dict				)
     # create random numpy tensors
     _snake_case   	=      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
     _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
     _snake_case   	=      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    :	Optional[int]				):



     """simple docstring"""
     # Initialize image_processing
     _snake_case   	=      self.image_processing_class(**self.image_processor_dict				)
     # create random PyTorch tensors
     _snake_case   	=      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
     _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
     _snake_case   	=      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'''],
         )							,       )










from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowercase    	=		{
    "configuration_mctct": ["MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP", "MCTCTConfig"],
    "feature_extraction_mctct": ["MCTCTFeatureExtractor"],
    "processing_mctct": ["MCTCTProcessor"],
}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _lowercase    	=		[
       "MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST",
       "MCTCTForCTC",
       "MCTCTModel",
       "MCTCTPreTrainedModel",
   ]


if TYPE_CHECKING:
   from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
   from .feature_extraction_mctct import MCTCTFeatureExtractor
   from .processing_mctct import MCTCTProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
   import sys

   _lowercase    	=		_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
