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






class    _UpperCAmelCase(   unittest.TestCase     ):



		def __init__( self    ,		__a    ,		__a=7    ,		__a=3    ,		__a=18    ,		__a=30    ,		__a=4_00    ,		__a=True    ,		__a=None    ,		__a=True    ,		__a=None    ,		__a=True    ,		__a=[0.5, 0.5, 0.5]    ,		__a=[0.5, 0.5, 0.5]    ,		)	->	str:






							'''simple docstring'''
							_UpperCamelCase										=  size if size is not None else {'''shortest_edge''': 18}
							_UpperCamelCase										=  crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
							_UpperCamelCase										=  parent
							_UpperCamelCase										=  batch_size
							_UpperCamelCase										=  num_channels
							_UpperCamelCase										=  image_size
							_UpperCamelCase										=  min_resolution
							_UpperCamelCase										=  max_resolution
							_UpperCamelCase										=  do_resize
							_UpperCamelCase										=  size
							_UpperCamelCase										=  do_center_crop
							_UpperCamelCase										=  crop_size
							_UpperCamelCase										=  do_normalize
							_UpperCamelCase										=  image_mean
							_UpperCamelCase										=  image_std




		def 						UpperCAmelCase							( self)	->	List[Any]:






							'''simple docstring'''
							return {
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							    "do_normalize": self.do_normalize,
							    "do_resize": self.do_resize,
							    "do_center_crop": self.do_center_crop,
							    "size": self.size,
							    "crop_size": self.crop_size,
							}






@require_torch
@require_vision
class    _UpperCAmelCase(   lowerCamelCase				,					unittest.TestCase     ):
		lowercase__      =				LevitImageProcessor if is_vision_available() else None



		def 						UpperCAmelCase							( self)	->	Optional[int]:






							'''simple docstring'''
							_UpperCamelCase										=  LevitImageProcessingTester(self)



		@property
		def 						UpperCAmelCase							( self)	->	Any:






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



		def 						UpperCAmelCase							( self)	->	List[Any]:






							'''simple docstring'''
							_UpperCamelCase										=  self.image_processing_class(**self.image_processor_dict)
							self.assertTrue(hasattr(__a    ,		'''image_mean'''))
							self.assertTrue(hasattr(__a    ,		'''image_std'''))
							self.assertTrue(hasattr(__a    ,		'''do_normalize'''))
							self.assertTrue(hasattr(__a    ,		'''do_resize'''))
							self.assertTrue(hasattr(__a    ,		'''do_center_crop'''))
							self.assertTrue(hasattr(__a    ,		'''size'''))



		def 						UpperCAmelCase							( self)	->	Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase										=  self.image_processing_class.from_dict(self.image_processor_dict)
							self.assertEqual(image_processor.size    ,		{'''shortest_edge''': 18})
							self.assertEqual(image_processor.crop_size    ,		{'''height''': 18, '''width''': 18})

							_UpperCamelCase										=  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 						UpperCAmelCase							( self)	->	Union[str, Any]:






							'''simple docstring'''
							pass



		def 						UpperCAmelCase							( self)	->	Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase										=  self.image_processing_class(**self.image_processor_dict)
							# create random PIL images
							_UpperCamelCase										=  prepare_image_inputs(self.image_processor_tester    ,		equal_resolution=__a)
							for image in image_inputs:
												self.assertIsInstance(__a    ,		Image.Image)

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



		def 						UpperCAmelCase							( self)	->	int:






							'''simple docstring'''
							_UpperCamelCase										=  self.image_processing_class(**self.image_processor_dict)
							# create random numpy tensors
							_UpperCamelCase										=  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
							_UpperCamelCase										=  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										=  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.crop_size['''height'''],
							        self.image_processor_tester.crop_size['''width'''],
							    )    ,		)




		def 						UpperCAmelCase							( self)	->	List[Any]:






							'''simple docstring'''
							_UpperCamelCase										=  self.image_processing_class(**self.image_processor_dict)
							# create random PyTorch tensors
							_UpperCamelCase										=  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
							_UpperCamelCase										=  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										=  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.crop_size['''height'''],
							        self.image_processor_tester.crop_size['''width'''],
							    )    ,		)








"""simple docstring"""





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


_a														=		{
    """configuration_trocr""": ["""TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TrOCRConfig"""],
    """processing_trocr""": ["""TrOCRProcessor"""],
}


try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_a														=		[
				    """TROCR_PRETRAINED_MODEL_ARCHIVE_LIST""",
				    """TrOCRForCausalLM""",
				    """TrOCRPreTrainedModel""",
				]


if TYPE_CHECKING:
				from .configuration_trocr import TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP, TrOCRConfig
				from .processing_trocr import TrOCRProcessor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_trocr import TROCR_PRETRAINED_MODEL_ARCHIVE_LIST, TrOCRForCausalLM, TrOCRPreTrainedModel

else:
				import sys

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






