'''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     a__( unittest.TestCase     ):


			'''simple docstring'''






			def __init__(       self	,   __lowerCAmelCase	,   __lowerCAmelCase=7	,   __lowerCAmelCase=3	,   __lowerCAmelCase=18	,   __lowerCAmelCase=30	,   __lowerCAmelCase=400	,   __lowerCAmelCase=True	,   __lowerCAmelCase=None	,   __lowerCAmelCase=0.875	,   __lowerCAmelCase=True	,   __lowerCAmelCase=[0.5, 0.5, 0.5]	,   __lowerCAmelCase=[0.5, 0.5, 0.5]	,   ):




					"""simple docstring"""


					lowerCAmelCase        =  size if size is not None else {"""shortest_edge""": 20}
					lowerCAmelCase        =  parent
					lowerCAmelCase        =  batch_size
					lowerCAmelCase        =  num_channels
					lowerCAmelCase        =  image_size
					lowerCAmelCase        =  min_resolution
					lowerCAmelCase        =  max_resolution
					lowerCAmelCase        =  do_resize
					lowerCAmelCase        =  size
					lowerCAmelCase        =  crop_pct
					lowerCAmelCase        =  do_normalize
					lowerCAmelCase        =  image_mean
					lowerCAmelCase        =  image_std







			def 							a_	(       self):




					"""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     a__( _a			,						unittest.TestCase     ):


			'''simple docstring'''






			UpperCAmelCase_      :					Dict								=	ConvNextImageProcessor if is_vision_available() else None



			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  ConvNextImageProcessingTester(self)



			@property
			def 							a_	(       self):




					"""simple docstring"""


					return self.image_processor_tester.prepare_image_processor_dict()



			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  self.image_processing_class(**self.image_processor_dict)
					self.assertTrue(hasattr(snake_case_	,   """do_resize"""))
					self.assertTrue(hasattr(snake_case_	,   """size"""))
					self.assertTrue(hasattr(snake_case_	,   """crop_pct"""))
					self.assertTrue(hasattr(snake_case_	,   """do_normalize"""))
					self.assertTrue(hasattr(snake_case_	,   """image_mean"""))
					self.assertTrue(hasattr(snake_case_	,   """image_std"""))



			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  self.image_processing_class.from_dict(self.image_processor_dict)
					self.assertEqual(image_processor.size	,   {"""shortest_edge""": 20})

					lowerCAmelCase        =  self.image_processing_class.from_dict(self.image_processor_dict	,   size=42)
					self.assertEqual(image_processor.size	,   {"""shortest_edge""": 42})



			def 							a_	(       self):




					"""simple docstring"""


					pass



			def 							a_	(       self):




					"""simple docstring"""


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

					# Test not batched input
					lowerCAmelCase        =  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        =  image_processing(snake_case_	,   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 							a_	(       self):




					"""simple docstring"""


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

					# Test not batched input
					lowerCAmelCase        =  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        =  image_processing(snake_case_	,   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 							a_	(       self):




					"""simple docstring"""


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

					# Test not batched input
					lowerCAmelCase        =  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        =  image_processing(snake_case_	,   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'''




from ..utils import DummyObject, requires_backends






class     a__( metaclass=lowerCAmelCase__     ):


			'''simple docstring'''






			UpperCAmelCase_      :					Optional[int]								=	['''torch''', '''transformers''', '''k_diffusion''']



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




					"""simple docstring"""


					requires_backends(self	,   ["""torch""", """transformers""", """k_diffusion"""])



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




					"""simple docstring"""


					requires_backends(cls	,   ["""torch""", """transformers""", """k_diffusion"""])







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




					"""simple docstring"""


					requires_backends(cls	,   ["""torch""", """transformers""", """k_diffusion"""])




