



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 GLPNImageProcessor






class 							lowercase__     (							unittest.TestCase       ):





	def __init__(			self :    str			,lowerCamelCase__ :    List[Any]			,lowerCamelCase__ :    Optional[int]=7			,lowerCamelCase__ :    Optional[int]=3			,lowerCamelCase__ :    List[Any]=18			,lowerCamelCase__ :    List[str]=30			,lowerCamelCase__ :    Any=400			,lowerCamelCase__ :    Optional[Any]=True			,lowerCamelCase__ :    List[Any]=32			,lowerCamelCase__ :    str=True			,):







							'''simple docstring'''
							_UpperCamelCase :		List[str]			    =       parent
							_UpperCamelCase :		List[Any]			    =       batch_size
							_UpperCamelCase :		Tuple			    =       num_channels
							_UpperCamelCase :		Union[str, Any]			    =       image_size
							_UpperCamelCase :		Any			    =       min_resolution
							_UpperCamelCase :		Optional[int]			    =       max_resolution
							_UpperCamelCase :		str			    =       do_resize
							_UpperCamelCase :		Optional[int]			    =       size_divisor
							_UpperCamelCase :		int			    =       do_rescale





	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							return {
							    "do_resize": self.do_resize,
							    "size_divisor": self.size_divisor,
							    "do_rescale": self.do_rescale,
							}






@require_torch
@require_vision
class 							lowercase__     (							lowercase						, unittest.TestCase       ):
	lowercase__      =      GLPNImageProcessor if is_vision_available() else None





	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							_UpperCamelCase :		int			    =       GLPNImageProcessingTester(self			)





	@property
	def      UpperCamelCase_  (			self :    Tuple			):







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





	def      UpperCamelCase_  (			self :    Union[str, Any]			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[Any]			    =       self.image_processing_class(**self.image_processor_dict			)
							self.assertTrue(hasattr(lowerCamelCase__			,'do_resize'			)			)
							self.assertTrue(hasattr(lowerCamelCase__			,'size_divisor'			)			)
							self.assertTrue(hasattr(lowerCamelCase__			,'resample'			)			)
							self.assertTrue(hasattr(lowerCamelCase__			,'do_rescale'			)			)





	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							pass





	def      UpperCamelCase_  (			self :    Union[str, Any]			):







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

							# Test not batched input (GLPNImageProcessor doesn't support batching)
							_UpperCamelCase :		List[str]			    =       image_processing(image_inputs[0]			,return_tensors='pt'			).pixel_values
							self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0			)
							self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0			)





	def      UpperCamelCase_  (			self :    Dict			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       self.image_processing_class(**self.image_processor_dict			)
							# create random numpy tensors
							_UpperCamelCase :		Union[str, Any]			    =       prepare_image_inputs(self.image_processor_tester			,equal_resolution=lowerCamelCase__			,numpify=lowerCamelCase__			)
							for image in image_inputs:
													self.assertIsInstance(lowerCamelCase__			,np.ndarray			)

							# Test not batched input (GLPNImageProcessor doesn't support batching)
							_UpperCamelCase :		Optional[int]			    =       image_processing(image_inputs[0]			,return_tensors='pt'			).pixel_values
							self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0			)
							self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0			)





	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							_UpperCamelCase :		List[str]			    =       self.image_processing_class(**self.image_processor_dict			)
							# create random PyTorch tensors
							_UpperCamelCase :		Any			    =       prepare_image_inputs(self.image_processor_tester			,equal_resolution=lowerCamelCase__			,torchify=lowerCamelCase__			)
							for image in image_inputs:
													self.assertIsInstance(lowerCamelCase__			,torch.Tensor			)

							# Test not batched input (GLPNImageProcessor doesn't support batching)
							_UpperCamelCase :		Dict			    =       image_processing(image_inputs[0]			,return_tensors='pt'			).pixel_values
							self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0			)
							self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0			)







'''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,
)


snake_case_			:     Optional[Any]  	=  {
    '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:
					snake_case_			:     Optional[int]  	=  ['CLIPTokenizerFast']

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

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

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     List[Any]  	=  [
					    'TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFCLIPModel',
					    'TFCLIPPreTrainedModel',
					    'TFCLIPTextModel',
					    'TFCLIPVisionModel',
					]

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     Optional[int]  	=  [
					    '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

					snake_case_			:     str  	=  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


