






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_video_inputs


if is_torch_available():
	import torch

if is_vision_available():
	from PIL import Image

	from transformers import VivitImageProcessor



class 							SCREAMING_SNAKE_CASE__						(    unittest.TestCase						):





					"""simple docstring"""






					def __init__( self					:  Dict							,		__A					:  Tuple							,		__A					:  Optional[int]=7							,		__A					:  Union[str, Any]=3							,		__A					:  Union[str, Any]=1_0							,		__A					:  List[Any]=1_8							,		__A					:  Any=3_0							,		__A					:  Optional[int]=4_0_0							,		__A					:  List[Any]=True							,		__A					:  int=None							,		__A					:  str=True							,		__A					:  Optional[Any]=[0.5, 0.5, 0.5]							,		__A					:  int=[0.5, 0.5, 0.5]							,		__A					:  Optional[Any]=None							,		):
						snake_case__			:				Optional[Any]       =  size if size is not None else {"shortest_edge": 1_8}
						snake_case__			:				List[Any]       =  crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}

						snake_case__			:				Dict       =  parent
						snake_case__			:				str       =  batch_size
						snake_case__			:				int       =  num_channels
						snake_case__			:				Optional[Any]       =  num_frames
						snake_case__			:				List[Any]       =  image_size
						snake_case__			:				Optional[Any]       =  min_resolution
						snake_case__			:				Optional[Any]       =  max_resolution
						snake_case__			:				Union[str, Any]       =  do_resize
						snake_case__			:				Optional[int]       =  size
						snake_case__			:				List[Any]       =  do_normalize
						snake_case__			:				int       =  image_mean
						snake_case__			:				List[str]       =  image_std
						snake_case__			:				List[str]       =  crop_size






					def 	_lowercase					( self					:  Union[str, Any]	):
						return {
						    "image_mean": self.image_mean,
						    "image_std": self.image_std,
						    "do_normalize": self.do_normalize,
						    "do_resize": self.do_resize,
						    "size": self.size,
						    "crop_size": self.crop_size,
						}



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





					"""simple docstring"""






					a_     =		VivitImageProcessor if is_vision_available() else None



					def 	_lowercase					( self					:  Union[str, Any]	):
						snake_case__			:				Tuple       =  VivitImageProcessingTester(self	)



					@property
					def 	_lowercase					( self					:  Any	):
						return self.image_processor_tester.prepare_image_processor_dict()



					def 	_lowercase					( self					:  str	):
						snake_case__			:				Any       =  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 	_lowercase					( self					:  Optional[Any]	):
						snake_case__			:				Union[str, Any]       =  self.image_processing_class.from_dict(self.image_processor_dict	)
						self.assertEqual(image_processor.size							,		{"shortest_edge": 1_8}	)
						self.assertEqual(image_processor.crop_size							,		{"height": 1_8, "width": 1_8}	)

						snake_case__			:				int       =  self.image_processing_class.from_dict(self.image_processor_dict							,		size=4_2							,		crop_size=8_4	)
						self.assertEqual(image_processor.size							,		{"shortest_edge": 4_2}	)
						self.assertEqual(image_processor.crop_size							,		{"height": 8_4, "width": 8_4}	)



					def 	_lowercase					( self					:  Any	):
						# Initialize image_processing
						snake_case__			:				str       =  self.image_processing_class(**self.image_processor_dict	)
						# create random PIL videos
						snake_case__			:				Optional[Any]       =  prepare_video_inputs(self.image_processor_tester							,		equal_resolution=__A	)
						for video in video_inputs:
							self.assertIsInstance(__A							,		__A	)
							self.assertIsInstance(video[0]							,		Image.Image	)

						# Test not batched input
						snake_case__			:				int       =  image_processing(video_inputs[0]							,		return_tensors="pt"	).pixel_values
						self.assertEqual(
						    encoded_videos.shape							,		(
						        1,
						        self.image_processor_tester.num_frames,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["height"],
						        self.image_processor_tester.crop_size["width"],
						    )							,		)

						# Test batched
						snake_case__			:				List[str]       =  image_processing(__A							,		return_tensors="pt"	).pixel_values
						self.assertEqual(
						    encoded_videos.shape							,		(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_frames,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["height"],
						        self.image_processor_tester.crop_size["width"],
						    )							,		)



					def 	_lowercase					( self					:  Optional[Any]	):
						# Initialize image_processing
						snake_case__			:				int       =  self.image_processing_class(**self.image_processor_dict	)
						# create random numpy tensors
						snake_case__			:				Any       =  prepare_video_inputs(self.image_processor_tester							,		equal_resolution=__A							,		numpify=__A	)
						for video in video_inputs:
							self.assertIsInstance(__A							,		__A	)
							self.assertIsInstance(video[0]							,		np.ndarray	)

						# Test not batched input
						snake_case__			:				Dict       =  image_processing(video_inputs[0]							,		return_tensors="pt"	).pixel_values
						self.assertEqual(
						    encoded_videos.shape							,		(
						        1,
						        self.image_processor_tester.num_frames,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["height"],
						        self.image_processor_tester.crop_size["width"],
						    )							,		)

						# Test batched
						snake_case__			:				List[str]       =  image_processing(__A							,		return_tensors="pt"	).pixel_values
						self.assertEqual(
						    encoded_videos.shape							,		(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_frames,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["height"],
						        self.image_processor_tester.crop_size["width"],
						    )							,		)






					def 	_lowercase					( self					:  int	):
						# Initialize image_processing
						snake_case__			:				str       =  self.image_processing_class(**self.image_processor_dict	)
						# create random PyTorch tensors
						snake_case__			:				Tuple       =  prepare_video_inputs(self.image_processor_tester							,		equal_resolution=__A							,		torchify=__A	)
						for video in video_inputs:
							self.assertIsInstance(__A							,		__A	)
							self.assertIsInstance(video[0]							,		torch.Tensor	)

						# Test not batched input
						snake_case__			:				str       =  image_processing(video_inputs[0]							,		return_tensors="pt"	).pixel_values
						self.assertEqual(
						    encoded_videos.shape							,		(
						        1,
						        self.image_processor_tester.num_frames,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["height"],
						        self.image_processor_tester.crop_size["width"],
						    )							,		)

						# Test batched
						snake_case__			:				List[Any]       =  image_processing(__A							,		return_tensors="pt"	).pixel_values
						self.assertEqual(
						    encoded_videos.shape							,		(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_frames,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["height"],
						        self.image_processor_tester.crop_size["width"],
						    )							,		)











from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCamelCase :      Any										=				{
    """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:
	__lowerCamelCase :      List[Any]										=				[
	    """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

	__lowerCamelCase :      Any										=				_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



