






'''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 MobileNetVaImageProcessor




class 					__UpperCAmelCase (		unittest.TestCase	):

      '''simple docstring'''





      def __init__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase=7  ,		_UpperCAmelCase=3  ,		_UpperCAmelCase=18  ,		_UpperCAmelCase=30  ,		_UpperCAmelCase=400  ,		_UpperCAmelCase=True  ,		_UpperCAmelCase=None  ,		_UpperCAmelCase=True  ,		_UpperCAmelCase=None  ,		):
             UpperCAmelCase__	:   Optional[Any]												=	size if size is not None else {'''shortest_edge''': 20}
             UpperCAmelCase__	:   List[Any]												=	crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
             UpperCAmelCase__	:   Optional[Any]												=	parent
             UpperCAmelCase__	:   Optional[int]												=	batch_size
             UpperCAmelCase__	:   Dict												=	num_channels
             UpperCAmelCase__	:   Tuple												=	image_size
             UpperCAmelCase__	:   Dict												=	min_resolution
             UpperCAmelCase__	:   List[str]												=	max_resolution
             UpperCAmelCase__	:   Any												=	do_resize
             UpperCAmelCase__	:   List[Any]												=	size
             UpperCAmelCase__	:   Optional[int]												=	do_center_crop
             UpperCAmelCase__	:   List[Any]												=	crop_size




      def 							lowerCamelCase     (					self						):
             return {
                 "do_resize": self.do_resize,
                 "size": self.size,
                 "do_center_crop": self.do_center_crop,
                 "crop_size": self.crop_size,
             }




@require_torch
@require_vision
class 					__UpperCAmelCase (		UpperCamelCase__      ,				unittest.TestCase	):

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    str				       =					MobileNetVaImageProcessor if is_vision_available() else None




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   int												=	MobileNetVaImageProcessingTester(self						)




      @property
      def 							lowerCamelCase     (					self						):
             return self.image_processor_tester.prepare_image_processor_dict()




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Union[str, Any]												=	self.image_processing_class(**self.image_processor_dict						)
             self.assertTrue(hasattr(_UpperCAmelCase  ,		'''do_resize'''						)						)
             self.assertTrue(hasattr(_UpperCAmelCase  ,		'''size'''						)						)
             self.assertTrue(hasattr(_UpperCAmelCase  ,		'''do_center_crop'''						)						)
             self.assertTrue(hasattr(_UpperCAmelCase  ,		'''center_crop'''						)						)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Optional[int]												=	self.image_processing_class.from_dict(self.image_processor_dict						)
             self.assertEqual(image_processor.size  ,		{'''shortest_edge''': 20}						)
             self.assertEqual(image_processor.crop_size  ,		{'''height''': 18, '''width''': 18}						)

             UpperCAmelCase__	:   Any												=	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 							lowerCamelCase     (					self						):
             pass




      def 							lowerCamelCase     (					self						):
             # Initialize image_processing
             UpperCAmelCase__	:   Tuple												=	self.image_processing_class(**self.image_processor_dict						)
             # create random PIL images
             UpperCAmelCase__	:   Dict												=	prepare_image_inputs(self.image_processor_tester  ,		equal_resolution=_UpperCAmelCase						)
             for image in image_inputs:
                    self.assertIsInstance(_UpperCAmelCase  ,		Image.Image						)

             # Test not batched input
             UpperCAmelCase__	:   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.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)

             # Test batched
             UpperCAmelCase__	:   Dict												=	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.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)




      def 							lowerCamelCase     (					self						):
             # Initialize image_processing
             UpperCAmelCase__	:   Optional[Any]												=	self.image_processing_class(**self.image_processor_dict						)
             # create random numpy tensors
             UpperCAmelCase__	:   Tuple												=	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
             UpperCAmelCase__	:   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.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)

             # Test batched
             UpperCAmelCase__	:   Optional[int]												=	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.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)




      def 							lowerCamelCase     (					self						):
             # Initialize image_processing
             UpperCAmelCase__	:   int												=	self.image_processing_class(**self.image_processor_dict						)
             # create random PyTorch tensors
             UpperCAmelCase__	:   Dict												=	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
             UpperCAmelCase__	:   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__	:   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.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)







'''simple docstring'''







import re






def  lowerCAmelCase__		(					a_  :     Optional[int]			)   -> Optional[Any]:
       def docstring_decorator(a_  :     Dict			):
              UpperCAmelCase__	:   Optional[int]												=	fn.__doc__
              UpperCAmelCase__	:   Dict												=	func_doc.split('''\n'''			)
              UpperCAmelCase__	:   Any												=	0
              while i < len(a_			) and re.search(r'''^\s*Examples?:\s*$'''			,						lines[i]			) is None:
                     i += 1
              if i < len(a_			):
                     UpperCAmelCase__	:   List[Any]												=	example_docstring
                     UpperCAmelCase__	:   int												=	'''\n'''.join(a_			)
              else:
                     raise ValueError(
                         f"""The function {fn} should have an empty 'Examples:' in its docstring as placeholder, """
                         f"""current docstring is:\n{func_doc}"""			)
              UpperCAmelCase__	:   Any												=	func_doc
              return fn

       return docstring_decorator