

"""simple docstring"""





import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor







class 				SCREAMING_SNAKE_CASE					(		unittest.TestCase       ):






					"""simple docstring"""



					def __init__(       self			:				Tuple   ,lowercase_			:				Dict   ,lowercase_			:				int=7   ,lowercase_			:				str=3   ,lowercase_			:				List[Any]=1_8   ,lowercase_			:				Any=3_0   ,lowercase_			:				str=4_0_0   ,lowercase_			:				List[str]=True   ,lowercase_			:				int=None   ,lowercase_			:				Tuple=True   ,lowercase_			:				Union[str, Any]=False   ,lowercase_			:				Union[str, Any]=True   ,lowercase_			:				Union[str, Any]=True   ,lowercase_			:				str=[0.5, 0.5, 0.5]   ,lowercase_			:				Any=[0.5, 0.5, 0.5]   ,):
						lowerCAmelCase__	:						Any  				=	parent
						lowerCAmelCase__	:						Tuple  				=	batch_size
						lowerCAmelCase__	:						Any  				=	num_channels
						lowerCAmelCase__	:						Tuple  				=	image_size
						lowerCAmelCase__	:						str  				=	min_resolution
						lowerCAmelCase__	:						Optional[Any]  				=	max_resolution
						lowerCAmelCase__	:						str  				=	do_resize
						lowerCAmelCase__	:						Dict  				=	size if size is not None else {'''height''': 1_8, '''width''': 2_0}
						lowerCAmelCase__	:						Union[str, Any]  				=	do_thumbnail
						lowerCAmelCase__	:						List[Any]  				=	do_align_axis
						lowerCAmelCase__	:						List[str]  				=	do_pad
						lowerCAmelCase__	:						List[str]  				=	do_normalize
						lowerCAmelCase__	:						Union[str, Any]  				=	image_mean
						lowerCAmelCase__	:						Tuple  				=	image_std







					def        __lowerCAmelCase (       self			:				List[Any]		):
						return {
						    "do_resize": self.do_resize,
						    "size": self.size,
						    "do_thumbnail": self.do_thumbnail,
						    "do_align_long_axis": self.do_align_axis,
						    "do_pad": self.do_pad,
						    "do_normalize": self.do_normalize,
						    "image_mean": self.image_mean,
						    "image_std": self.image_std,
						}







@require_torch
@require_vision
class 				SCREAMING_SNAKE_CASE					(		a_    ,							unittest.TestCase       ):






					"""simple docstring"""



					lowercase__				 =       DonutImageProcessor if is_vision_available() else None







					def        __lowerCAmelCase (       self			:				List[str]		):
						lowerCAmelCase__	:						Dict  				=	DonutImageProcessingTester(self		)







					@property
					def        __lowerCAmelCase (       self			:				Optional[Any]		):
						return self.image_processor_tester.prepare_image_processor_dict()







					def        __lowerCAmelCase (       self			:				str		):
						lowerCAmelCase__	:						Optional[Any]  				=	self.image_processing_class(**self.image_processor_dict		)
						self.assertTrue(hasattr(lowercase_   ,'''do_resize'''		)		)
						self.assertTrue(hasattr(lowercase_   ,'''size'''		)		)
						self.assertTrue(hasattr(lowercase_   ,'''do_thumbnail'''		)		)
						self.assertTrue(hasattr(lowercase_   ,'''do_align_long_axis'''		)		)
						self.assertTrue(hasattr(lowercase_   ,'''do_pad'''		)		)
						self.assertTrue(hasattr(lowercase_   ,'''do_normalize'''		)		)
						self.assertTrue(hasattr(lowercase_   ,'''image_mean'''		)		)
						self.assertTrue(hasattr(lowercase_   ,'''image_std'''		)		)







					def        __lowerCAmelCase (       self			:				Tuple		):
						lowerCAmelCase__	:						Any  				=	self.image_processing_class.from_dict(self.image_processor_dict		)
						self.assertEqual(image_processor.size   ,{'''height''': 1_8, '''width''': 2_0}		)

						lowerCAmelCase__	:						Optional[int]  				=	self.image_processing_class.from_dict(self.image_processor_dict   ,size=4_2		)
						self.assertEqual(image_processor.size   ,{'''height''': 4_2, '''width''': 4_2}		)

						# Previous config had dimensions in (width, height) order
						lowerCAmelCase__	:						int  				=	self.image_processing_class.from_dict(self.image_processor_dict   ,size=(4_2, 8_4)		)
						self.assertEqual(image_processor.size   ,{'''height''': 8_4, '''width''': 4_2}		)







					def        __lowerCAmelCase (       self			:				Optional[int]		):
						pass







					@is_flaky()
					def        __lowerCAmelCase (       self			:				Optional[Any]		):
						# Initialize image_processing
						lowerCAmelCase__	:						List[Any]  				=	self.image_processing_class(**self.image_processor_dict		)
						# create random PIL images
						lowerCAmelCase__	:						Tuple  				=	prepare_image_inputs(self.image_processor_tester   ,equal_resolution=lowercase_		)
						for image in image_inputs:
							self.assertIsInstance(lowercase_   ,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['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )   ,)

						# Test batched
						lowerCAmelCase__	:						List[Any]  				=	image_processing(lowercase_   ,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['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )   ,)







					@is_flaky()
					def        __lowerCAmelCase (       self			:				Tuple		):
						# Initialize image_processing
						lowerCAmelCase__	:						int  				=	self.image_processing_class(**self.image_processor_dict		)
						# create random numpy tensors
						lowerCAmelCase__	:						Optional[int]  				=	prepare_image_inputs(self.image_processor_tester   ,equal_resolution=lowercase_   ,numpify=lowercase_		)
						for image in image_inputs:
							self.assertIsInstance(lowercase_   ,np.ndarray		)

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

						# Test batched
						lowerCAmelCase__	:						Optional[Any]  				=	image_processing(lowercase_   ,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['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )   ,)







					@is_flaky()
					def        __lowerCAmelCase (       self			:				str		):
						# Initialize image_processing
						lowerCAmelCase__	:						Dict  				=	self.image_processing_class(**self.image_processor_dict		)
						# create random PyTorch tensors
						lowerCAmelCase__	:						int  				=	prepare_image_inputs(self.image_processor_tester   ,equal_resolution=lowercase_   ,torchify=lowercase_		)
						for image in image_inputs:
							self.assertIsInstance(lowercase_   ,torch.Tensor		)

						# 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['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )   ,)

						# Test batched
						lowerCAmelCase__	:						Any  				=	image_processing(lowercase_   ,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['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )   ,)







"""simple docstring"""





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


__UpperCamelCase  :      Dict							      =		{
    '''configuration_clip''': [
        '''CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''CLIPConfig''',
        '''CLIPOnnxConfig''',
        '''CLIPTextConfig''',
        '''CLIPVisionConfig''',
    ],
    '''processing_clip''': ['''CLIPProcessor'''],
    '''tokenization_clip''': ['''CLIPTokenizer'''],
}

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__UpperCamelCase  :      int							      =		['''CLIPTokenizerFast''']

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__UpperCamelCase  :      Optional[int]							      =		['''CLIPFeatureExtractor''']
							__UpperCamelCase  :      Optional[Any]							      =		['''CLIPImageProcessor''']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__UpperCamelCase  :      Tuple							      =		[
							    '''CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''CLIPModel''',
							    '''CLIPPreTrainedModel''',
							    '''CLIPTextModel''',
							    '''CLIPTextModelWithProjection''',
							    '''CLIPVisionModel''',
							    '''CLIPVisionModelWithProjection''',
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__UpperCamelCase  :      Optional[int]							      =		[
							    '''TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''TFCLIPModel''',
							    '''TFCLIPPreTrainedModel''',
							    '''TFCLIPTextModel''',
							    '''TFCLIPVisionModel''',
							]

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__UpperCamelCase  :      Optional[Any]							      =		[
							    '''FlaxCLIPModel''',
							    '''FlaxCLIPPreTrainedModel''',
							    '''FlaxCLIPTextModel''',
							    '''FlaxCLIPTextPreTrainedModel''',
							    '''FlaxCLIPVisionModel''',
							    '''FlaxCLIPVisionPreTrainedModel''',
							]


if TYPE_CHECKING:
							from .configuration_clip import (
							    CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    CLIPConfig,
							    CLIPOnnxConfig,
							    CLIPTextConfig,
							    CLIPVisionConfig,
							)
							from .processing_clip import CLIPProcessor
							from .tokenization_clip import CLIPTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_clip_fast import CLIPTokenizerFast

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_clip import CLIPFeatureExtractor
														from .image_processing_clip import CLIPImageProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_clip import (
														    CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
														    CLIPModel,
														    CLIPPreTrainedModel,
														    CLIPTextModel,
														    CLIPTextModelWithProjection,
														    CLIPVisionModel,
														    CLIPVisionModelWithProjection,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_clip import (
														    TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFCLIPModel,
														    TFCLIPPreTrainedModel,
														    TFCLIPTextModel,
														    TFCLIPVisionModel,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_clip import (
														    FlaxCLIPModel,
														    FlaxCLIPPreTrainedModel,
														    FlaxCLIPTextModel,
														    FlaxCLIPTextPreTrainedModel,
														    FlaxCLIPVisionModel,
														    FlaxCLIPVisionPreTrainedModel,
														)


else:
							import sys

							__UpperCamelCase  :      Tuple							      =		_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




