



'''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 							lowercase__	(							unittest.TestCase   ):





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







							'''simple docstring'''
							_UpperCamelCase					:		List[Any] 				=   size if size is not None else {'shortest_edge': 18}
							_UpperCamelCase					:		Union[str, Any] 				=   crop_size if crop_size is not None else {'height': 18, 'width': 18}
							_UpperCamelCase					:		Dict 				=   parent
							_UpperCamelCase					:		List[str] 				=   batch_size
							_UpperCamelCase					:		List[str] 				=   num_channels
							_UpperCamelCase					:		Optional[int] 				=   image_size
							_UpperCamelCase					:		Union[str, Any] 				=   min_resolution
							_UpperCamelCase					:		int 				=   max_resolution
							_UpperCamelCase					:		Tuple 				=   do_resize
							_UpperCamelCase					:		List[str] 				=   size
							_UpperCamelCase					:		int 				=   do_center_crop
							_UpperCamelCase					:		Dict 				=   crop_size
							_UpperCamelCase					:		List[str] 				=   do_normalize
							_UpperCamelCase					:		Optional[int] 				=   image_mean
							_UpperCamelCase					:		Optional[int] 				=   image_std





	def 	UpperCamelCase_  ( self					:				Union[str, 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 							lowercase__	(							lowerCAmelCase__						,					unittest.TestCase   ):
	lowercase__  				=			LevitImageProcessor if is_vision_available() else None





	def 	UpperCamelCase_  ( self					:				Optional[Any] ):







							'''simple docstring'''
							_UpperCamelCase					:		Optional[int] 				=   LevitImageProcessingTester(self )





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







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





	def 	UpperCamelCase_  ( self					:				List[Any] ):







							'''simple docstring'''
							_UpperCamelCase					:		Optional[Any] 				=   self.image_processing_class(**self.image_processor_dict )
							self.assertTrue(hasattr(__lowerCAmelCase ,'image_mean' ) )
							self.assertTrue(hasattr(__lowerCAmelCase ,'image_std' ) )
							self.assertTrue(hasattr(__lowerCAmelCase ,'do_normalize' ) )
							self.assertTrue(hasattr(__lowerCAmelCase ,'do_resize' ) )
							self.assertTrue(hasattr(__lowerCAmelCase ,'do_center_crop' ) )
							self.assertTrue(hasattr(__lowerCAmelCase ,'size' ) )





	def 	UpperCamelCase_  ( self					:				str ):







							'''simple docstring'''
							_UpperCamelCase					:		List[Any] 				=   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					:		Optional[int] 				=   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					:				Tuple ):







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

							# 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					:		Dict 				=   image_processing(__lowerCAmelCase ,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[str] ):







							'''simple docstring'''
							_UpperCamelCase					:		Union[str, Any] 				=   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
							_UpperCamelCase					:		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.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    ) ,)

							# Test batched
							_UpperCamelCase					:		List[Any] 				=   image_processing(__lowerCAmelCase ,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					:		List[str] 				=   self.image_processing_class(**self.image_processor_dict )
							# create random PyTorch tensors
							_UpperCamelCase					:		int 				=   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
							_UpperCamelCase					:		int 				=   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					:		int 				=   image_processing(__lowerCAmelCase ,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_torch_available


__lowercase          =  {
    '''configuration_instructblip''': [
        '''INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''InstructBlipConfig''',
        '''InstructBlipQFormerConfig''',
        '''InstructBlipVisionConfig''',
    ],
    '''processing_instructblip''': ['''InstructBlipProcessor'''],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__lowercase          =  [
						    '''INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''InstructBlipQFormerModel''',
						    '''InstructBlipPreTrainedModel''',
						    '''InstructBlipForConditionalGeneration''',
						    '''InstructBlipVisionModel''',
						]

if TYPE_CHECKING:
						from .configuration_instructblip import (
						    INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    InstructBlipConfig,
						    InstructBlipQFormerConfig,
						    InstructBlipVisionConfig,
						)
						from .processing_instructblip import InstructBlipProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_instructblip import (
												    INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
												    InstructBlipForConditionalGeneration,
												    InstructBlipPreTrainedModel,
												    InstructBlipQFormerModel,
												    InstructBlipVisionModel,
												)

else:
						import sys

						__lowercase          =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




