

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 ConvNextImageProcessor







class   __lowercase				(unittest.TestCase			):
 def __init__(							self				,							A_				,							A_=7				,							A_=3				,							A_=18				,							A_=30				,							A_=400				,							A_=True				,							A_=None				,							A_=0.875				,							A_=True				,							A_=[0.5, 0.5, 0.5]				,							A_=[0.5, 0.5, 0.5]				,							) ->Union[str, Any]:



       '''simple docstring'''





       __lowerCAmelCase :						List[str] = size if size is not None else {'''shortest_edge''': 20}
       __lowerCAmelCase :						str = parent
       __lowerCAmelCase :						Dict = batch_size
       __lowerCAmelCase :						int = num_channels
       __lowerCAmelCase :						Any = image_size
       __lowerCAmelCase :						Optional[Any] = min_resolution
       __lowerCAmelCase :						int = max_resolution
       __lowerCAmelCase :						Any = do_resize
       __lowerCAmelCase :						Dict = size
       __lowerCAmelCase :						Optional[int] = crop_pct
       __lowerCAmelCase :						int = do_normalize
       __lowerCAmelCase :						str = image_mean
       __lowerCAmelCase :						List[Any] = image_std





 def      UpperCamelCase__  (							self ) ->Tuple:



       '''simple docstring'''





       return {
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_normalize": self.do_normalize,
           "do_resize": self.do_resize,
           "size": self.size,
           "crop_pct": self.crop_pct,
       }







@require_torch
@require_vision
class   __lowercase				(_UpperCAmelCase		,       unittest.TestCase			):
 _UpperCamelCase        =  ConvNextImageProcessor if is_vision_available() else None
 def      UpperCamelCase__  (							self ) ->Any:



       '''simple docstring'''





       __lowerCAmelCase :						Any = ConvNextImageProcessingTester(self )
 @property
 def      UpperCamelCase__  (							self ) ->Tuple:



       '''simple docstring'''





       return self.image_processor_tester.prepare_image_processor_dict()
 def      UpperCamelCase__  (							self ) ->List[Any]:



       '''simple docstring'''





       __lowerCAmelCase :						Optional[Any] = self.image_processing_class(**self.image_processor_dict )
       self.assertTrue(hasattr(A_				,							'''do_resize''' ) )
       self.assertTrue(hasattr(A_				,							'''size''' ) )
       self.assertTrue(hasattr(A_				,							'''crop_pct''' ) )
       self.assertTrue(hasattr(A_				,							'''do_normalize''' ) )
       self.assertTrue(hasattr(A_				,							'''image_mean''' ) )
       self.assertTrue(hasattr(A_				,							'''image_std''' ) )
 def      UpperCamelCase__  (							self ) ->Tuple:



       '''simple docstring'''





       __lowerCAmelCase :						Any = self.image_processing_class.from_dict(self.image_processor_dict )
       self.assertEqual(image_processor.size				,							{'''shortest_edge''': 20} )

       __lowerCAmelCase :						str = self.image_processing_class.from_dict(self.image_processor_dict				,							size=42 )
       self.assertEqual(image_processor.size				,							{'''shortest_edge''': 42} )
 def      UpperCamelCase__  (							self ) ->Dict:



       '''simple docstring'''





       pass
 def      UpperCamelCase__  (							self ) ->Tuple:



       '''simple docstring'''





       __lowerCAmelCase :						Optional[int] = self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       __lowerCAmelCase :						str = prepare_image_inputs(self.image_processor_tester				,							equal_resolution=A_ )
       for image in image_inputs:
             self.assertIsInstance(A_				,							Image.Image )

       # Test not batched input
       __lowerCAmelCase :						Optional[int] = 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.size['''shortest_edge'''],
               self.image_processor_tester.size['''shortest_edge'''],
           )				,							)

       # Test batched
       __lowerCAmelCase :						Optional[Any] = image_processing(A_				,							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.size['''shortest_edge'''],
               self.image_processor_tester.size['''shortest_edge'''],
           )				,							)
 def      UpperCamelCase__  (							self ) ->Dict:



       '''simple docstring'''





       __lowerCAmelCase :						List[str] = self.image_processing_class(**self.image_processor_dict )
       # create random numpy tensors
       __lowerCAmelCase :						Tuple = prepare_image_inputs(self.image_processor_tester				,							equal_resolution=A_				,							numpify=A_ )
       for image in image_inputs:
             self.assertIsInstance(A_				,							np.ndarray )

       # Test not batched input
       __lowerCAmelCase :						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.size['''shortest_edge'''],
               self.image_processor_tester.size['''shortest_edge'''],
           )				,							)

       # Test batched
       __lowerCAmelCase :						Optional[Any] = image_processing(A_				,							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.size['''shortest_edge'''],
               self.image_processor_tester.size['''shortest_edge'''],
           )				,							)





 def      UpperCamelCase__  (							self ) ->Dict:



       '''simple docstring'''





       __lowerCAmelCase :						List[str] = self.image_processing_class(**self.image_processor_dict )
       # create random PyTorch tensors
       __lowerCAmelCase :						Union[str, Any] = prepare_image_inputs(self.image_processor_tester				,							equal_resolution=A_				,							torchify=A_ )
       for image in image_inputs:
             self.assertIsInstance(A_				,							torch.Tensor )

       # Test not batched input
       __lowerCAmelCase :						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.size['''shortest_edge'''],
               self.image_processor_tester.size['''shortest_edge'''],
           )				,							)

       # Test batched
       __lowerCAmelCase :						str = image_processing(A_				,							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.size['''shortest_edge'''],
               self.image_processor_tester.size['''shortest_edge'''],
           )				,							)





def 		_lowercase			(					lowercase__						):
      return "".join(chr(ord(lowercase__						) + 3_2						) if '''A''' <= char <= '''Z''' else char for char in word						)


if __name__ == "__main__":
 from doctest import testmod

 testmod()


