






"""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 ConvNextImageProcessor




class 	__UpperCamelCase    (    unittest.TestCase	):
					def __init__(       self       :  Dict    ,   UpperCAmelCase       :  str    ,   UpperCAmelCase       :  str=7    ,   UpperCAmelCase       :  int=3    ,   UpperCAmelCase       :  Dict=18    ,   UpperCAmelCase       :  Tuple=30    ,   UpperCAmelCase       :  Optional[Any]=400    ,   UpperCAmelCase       :  Union[str, Any]=True    ,   UpperCAmelCase       :  Dict=None    ,   UpperCAmelCase       :  Optional[Any]=0.8_7_5    ,   UpperCAmelCase       :  Tuple=True    ,   UpperCAmelCase       :  Union[str, Any]=[0.5, 0.5, 0.5]    ,   UpperCAmelCase       :  Union[str, Any]=[0.5, 0.5, 0.5]    ,   )  ->					List[Any]:
											lowerCAmelCase      :List[Any]				  = size if size is not None else {'shortest_edge': 20}
											lowerCAmelCase      :Dict				  = parent
											lowerCAmelCase      :Tuple				  = batch_size
											lowerCAmelCase      :List[str]				  = num_channels
											lowerCAmelCase      :Optional[Any]				  = image_size
											lowerCAmelCase      :List[Any]				  = min_resolution
											lowerCAmelCase      :List[str]				  = max_resolution
											lowerCAmelCase      :str				  = do_resize
											lowerCAmelCase      :str				  = size
											lowerCAmelCase      :str				  = crop_pct
											lowerCAmelCase      :List[str]				  = do_normalize
											lowerCAmelCase      :int				  = image_mean
											lowerCAmelCase      :int				  = image_std
					def 					UpperCAmelCase__   (       self       :  Optional[int]      )  ->					str:
											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 	__UpperCamelCase    (    UpperCamelCase      ,    unittest.TestCase	):
					lowercase_						:							List[Any]			=     ConvNextImageProcessor if is_vision_available() else None
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					Optional[Any]:
											lowerCAmelCase      :str				  = ConvNextImageProcessingTester(self      )
					@property
					def 					UpperCAmelCase__   (       self       :  Tuple      )  ->					Optional[int]:
											return self.image_processor_tester.prepare_image_processor_dict()
					def 					UpperCAmelCase__   (       self       :  Optional[int]      )  ->					str:
											lowerCAmelCase      :List[str]				  = self.image_processing_class(**self.image_processor_dict      )
											self.assertTrue(hasattr(UpperCAmelCase    ,   'do_resize'      )      )
											self.assertTrue(hasattr(UpperCAmelCase    ,   'size'      )      )
											self.assertTrue(hasattr(UpperCAmelCase    ,   'crop_pct'      )      )
											self.assertTrue(hasattr(UpperCAmelCase    ,   'do_normalize'      )      )
											self.assertTrue(hasattr(UpperCAmelCase    ,   'image_mean'      )      )
											self.assertTrue(hasattr(UpperCAmelCase    ,   'image_std'      )      )
					def 					UpperCAmelCase__   (       self       :  Optional[Any]      )  ->					List[str]:
											lowerCAmelCase      :Any				  = self.image_processing_class.from_dict(self.image_processor_dict      )
											self.assertEqual(image_processor.size    ,   {'shortest_edge': 20}      )

											lowerCAmelCase      :List[str]				  = self.image_processing_class.from_dict(self.image_processor_dict    ,   size=42      )
											self.assertEqual(image_processor.size    ,   {'shortest_edge': 42}      )
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					List[str]:
											pass
					def 					UpperCAmelCase__   (       self       :  Tuple      )  ->					str:
											# Initialize image_processing
											lowerCAmelCase      :List[str]				  = self.image_processing_class(**self.image_processor_dict      )
											# create random PIL images
											lowerCAmelCase      :str				  = prepare_image_inputs(self.image_processor_tester    ,   equal_resolution=UpperCAmelCase      )
											for image in image_inputs:
																	self.assertIsInstance(UpperCAmelCase    ,   Image.Image      )

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

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

											# 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      :Union[str, Any]				  = image_processing(UpperCAmelCase    ,   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       :  Optional[int]      )  ->					int:
											# Initialize image_processing
											lowerCAmelCase      :int				  = self.image_processing_class(**self.image_processor_dict      )
											# create random PyTorch tensors
											lowerCAmelCase      :Tuple				  = prepare_image_inputs(self.image_processor_tester    ,   equal_resolution=UpperCAmelCase    ,   torchify=UpperCAmelCase      )
											for image in image_inputs:
																	self.assertIsInstance(UpperCAmelCase    ,   torch.Tensor      )

											# Test not batched input
											lowerCAmelCase      :Union[str, 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(UpperCAmelCase    ,   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'],
											    )    ,   )







"""simple docstring"""


import safs




class 	__UpperCamelCase    (    safs.SaFileSystem	):
					pass