
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


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import CLIPImageProcessor




class      SCREAMING_SNAKE_CASE__  (			unittest.TestCase      ):





	'''simple docstring'''



	def __init__(						self			:					Dict    ,						lowercase			:					Optional[Any]    ,						lowercase			:					Optional[Any]=7    ,						lowercase			:					Any=3    ,						lowercase			:					Dict=18    ,						lowercase			:					List[Any]=30    ,						lowercase			:					Any=400    ,						lowercase			:					str=True    ,						lowercase			:					Dict=None    ,						lowercase			:					List[Any]=True    ,						lowercase			:					Dict=None    ,						lowercase			:					Any=True    ,						lowercase			:					str=[0.48145466, 0.4578275, 0.40821073]    ,						lowercase			:					Any=[0.26862954, 0.26130258, 0.27577711]    ,						lowercase			:					int=True    ,						):


				'''simple docstring'''


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



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


				'''simple docstring'''


				return {
				    "do_resize": self.do_resize,
				    "size": self.size,
				    "do_center_crop": self.do_center_crop,
				    "crop_size": self.crop_size,
				    "do_normalize": self.do_normalize,
				    "image_mean": self.image_mean,
				    "image_std": self.image_std,
				    "do_convert_rgb": self.do_convert_rgb,
				}





	def 				A							(						self			:					Union[str, Any]    ,						lowercase			:					Dict=False    ,						lowercase			:					Optional[int]=False    ,						lowercase			:					List[Any]=False			):


				'''simple docstring'''


				assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

				if equal_resolution:
							_snake_case						=    []
							for i in range(self.batch_size			):
										image_inputs.append(
										    np.random.randint(
										        255    ,						size=(self.num_channels, self.max_resolution, self.max_resolution)    ,						dtype=np.uinta			)			)
				else:
							_snake_case						=    []
							for i in range(self.batch_size			):
										_snake_case						=    np.random.choice(np.arange(self.min_resolution    ,						self.max_resolution			)    ,						2			)
										image_inputs.append(np.random.randint(255    ,						size=(self.num_channels, width, height)    ,						dtype=np.uinta			)			)

				if not numpify and not torchify:
							# PIL expects the channel dimension as last dimension
							_snake_case						=    [Image.fromarray(np.moveaxis(lowercase_    ,						0    ,						-1			)			) for x in image_inputs]

				if torchify:
							_snake_case						=    [torch.from_numpy(lowercase_			) for x in image_inputs]

				return image_inputs




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





	'''simple docstring'''



	_UpperCAmelCase :	List[Any]					     =      CLIPImageProcessor if is_vision_available() else None



	def 				A							(						self			:					List[str]			):


				'''simple docstring'''


				_snake_case						=    CLIPImageProcessingTester(self			)



	@property
	def 				A							(						self			:					Union[str, Any]			):


				'''simple docstring'''


				return self.image_processor_tester.prepare_image_processor_dict()



	def 				A							(						self			:					Tuple			):


				'''simple docstring'''


				_snake_case						=    self.image_processing_class(**self.image_processor_dict			)
				self.assertTrue(hasattr(lowercase_    ,						'do_resize'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'size'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'do_center_crop'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'center_crop'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'do_normalize'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'image_mean'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'image_std'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'do_convert_rgb'			)			)



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


				'''simple docstring'''


				_snake_case						=    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}			)

				_snake_case						=    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 				A							(						self			:					List[Any]			):


				'''simple docstring'''


				pass



	def 				A							(						self			:					str			):


				'''simple docstring'''


				_snake_case						=    self.image_processing_class(**self.image_processor_dict			)
				# create random PIL images
				_snake_case						=    self.image_processor_tester.prepare_inputs(equal_resolution=lowercase_			)
				for image in image_inputs:
							self.assertIsInstance(lowercase_    ,						Image.Image			)

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



	def 				A							(						self			:					int			):


				'''simple docstring'''


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

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





	def 				A							(						self			:					List[str]			):


				'''simple docstring'''


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

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




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





	'''simple docstring'''



	_UpperCAmelCase :	List[str]					     =      CLIPImageProcessor if is_vision_available() else None



	def 				A							(						self			:					Optional[int]			):


				'''simple docstring'''


				_snake_case						=    CLIPImageProcessingTester(self    ,						num_channels=4			)
				_snake_case						=    3



	@property
	def 				A							(						self			:					Tuple			):


				'''simple docstring'''


				return self.image_processor_tester.prepare_image_processor_dict()



	def 				A							(						self			:					str			):


				'''simple docstring'''


				_snake_case						=    self.image_processing_class(**self.image_processor_dict			)
				self.assertTrue(hasattr(lowercase_    ,						'do_resize'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'size'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'do_center_crop'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'center_crop'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'do_normalize'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'image_mean'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'image_std'			)			)
				self.assertTrue(hasattr(lowercase_    ,						'do_convert_rgb'			)			)



	def 				A							(						self			:					str			):


				'''simple docstring'''


				pass





	def 				A							(						self			:					List[Any]			):


				'''simple docstring'''


				_snake_case						=    self.image_processing_class(**self.image_processor_dict			)
				# create random PIL images
				_snake_case						=    self.image_processor_tester.prepare_inputs(equal_resolution=lowercase_			)
				for image in image_inputs:
							self.assertIsInstance(lowercase_    ,						Image.Image			)

				# Test not batched input
				_snake_case						=    image_processing(image_inputs[0]    ,						return_tensors='pt'			).pixel_values
				self.assertEqual(
				    encoded_images.shape    ,						(
				        1,
				        self.expected_encoded_image_num_channels,
				        self.image_processor_tester.crop_size['height'],
				        self.image_processor_tester.crop_size['width'],
				    )    ,						)

				# Test batched
				_snake_case						=    image_processing(lowercase_    ,						return_tensors='pt'			).pixel_values
				self.assertEqual(
				    encoded_images.shape    ,						(
				        self.image_processor_tester.batch_size,
				        self.expected_encoded_image_num_channels,
				        self.image_processor_tester.crop_size['height'],
				        self.image_processor_tester.crop_size['width'],
				    )    ,						)

# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


_lowerCamelCase :       int     					=    {
    '''configuration_tvlt''': ['''TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''TvltConfig'''],
    '''feature_extraction_tvlt''': ['''TvltFeatureExtractor'''],
    '''processing_tvlt''': ['''TvltProcessor'''],
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_lowerCamelCase :       str     					=    [
			    '''TVLT_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''TvltModel''',
			    '''TvltForPreTraining''',
			    '''TvltForAudioVisualClassification''',
			    '''TvltPreTrainedModel''',
			]

try:
			if not is_vision_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_lowerCamelCase :       str     					=    ['''TvltImageProcessor''']


if TYPE_CHECKING:
			from .configuration_tvlt import TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP, TvltConfig
			from .processing_tvlt import TvltProcessor
			from .feature_extraction_tvlt import TvltFeatureExtractor

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tvlt import (
						    TVLT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TvltForAudioVisualClassification,
						    TvltForPreTraining,
						    TvltModel,
						    TvltPreTrainedModel,
						)

			try:
						if not is_vision_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .image_processing_tvlt import TvltImageProcessor


else:
			import sys

			_lowerCamelCase :       Dict     					=    _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)