



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

			def __init__(self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_=7,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=10,   SCREAMING_SNAKE_CASE_=18,   SCREAMING_SNAKE_CASE_=30,   SCREAMING_SNAKE_CASE_=400,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=None,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5],   SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5],   SCREAMING_SNAKE_CASE_=None,   )       ->   Optional[int]:
						UpperCAmelCase_:		Optional[int]							      =     size if size is not None else {"""shortest_edge""": 18}
						UpperCAmelCase_:		int							      =     crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

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

			def      __snake_case       (self					)       ->   Optional[int]:
						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 				_a				(   _lowerCAmelCase ,		unittest.TestCase					):
			A      		=	VivitImageProcessor if is_vision_available() else None

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		Tuple							      =     VivitImageProcessingTester(self					)

			@property
			def      __snake_case       (self					)       ->   Union[str, Any]:
						return self.image_processor_tester.prepare_image_processor_dict()

			def      __snake_case       (self					)       ->   str:
						UpperCAmelCase_:		Optional[Any]							      =     self.image_processing_class(**self.image_processor_dict					)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """image_mean"""					)					)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """image_std"""					)					)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """do_normalize"""					)					)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """do_resize"""					)					)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """do_center_crop"""					)					)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """size"""					)					)

			def      __snake_case       (self					)       ->   str:
						UpperCAmelCase_:		Tuple							      =     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_:		List[Any]							      =     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      __snake_case       (self					)       ->   Union[str, Any]:
						# Initialize image_processing
						UpperCAmelCase_:		Tuple							      =     self.image_processing_class(**self.image_processor_dict					)
						# create random PIL videos
						UpperCAmelCase_:		Optional[Any]							      =     prepare_video_inputs(self.image_processor_tester,   equal_resolution=SCREAMING_SNAKE_CASE_					)
						for video in video_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)
									self.assertIsInstance(video[0],   Image.Image					)

						# Test not batched input
						UpperCAmelCase_:		List[Any]							      =     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
						UpperCAmelCase_:		List[str]							      =     image_processing(SCREAMING_SNAKE_CASE_,   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      __snake_case       (self					)       ->   Optional[Any]:
						# Initialize image_processing
						UpperCAmelCase_:		int							      =     self.image_processing_class(**self.image_processor_dict					)
						# create random numpy tensors
						UpperCAmelCase_:		Dict							      =     prepare_video_inputs(self.image_processor_tester,   equal_resolution=SCREAMING_SNAKE_CASE_,   numpify=SCREAMING_SNAKE_CASE_					)
						for video in video_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)
									self.assertIsInstance(video[0],   np.ndarray					)

						# Test not batched input
						UpperCAmelCase_:		Optional[Any]							      =     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
						UpperCAmelCase_:		Dict							      =     image_processing(SCREAMING_SNAKE_CASE_,   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      __snake_case       (self					)       ->   str:
						# Initialize image_processing
						UpperCAmelCase_:		int							      =     self.image_processing_class(**self.image_processor_dict					)
						# create random PyTorch tensors
						UpperCAmelCase_:		str							      =     prepare_video_inputs(self.image_processor_tester,   equal_resolution=SCREAMING_SNAKE_CASE_,   torchify=SCREAMING_SNAKE_CASE_					)
						for video in video_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)
									self.assertIsInstance(video[0],   torch.Tensor					)

						# Test not batched input
						UpperCAmelCase_:		Optional[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
						UpperCAmelCase_:		Tuple							      =     image_processing(SCREAMING_SNAKE_CASE_,   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_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


a      :  Dict			     =			{
    'configuration_lxmert': ['LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LxmertConfig'],
    'tokenization_lxmert': ['LxmertTokenizer'],
}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a      :  Any			     =			['LxmertTokenizerFast']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a      :  str			     =			[
	    'LxmertEncoder',
	    'LxmertForPreTraining',
	    'LxmertForQuestionAnswering',
	    'LxmertModel',
	    'LxmertPreTrainedModel',
	    'LxmertVisualFeatureEncoder',
	    'LxmertXLayer',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a      :  str			     =			[
	    'TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'TFLxmertForPreTraining',
	    'TFLxmertMainLayer',
	    'TFLxmertModel',
	    'TFLxmertPreTrainedModel',
	    'TFLxmertVisualFeatureEncoder',
	]


if TYPE_CHECKING:
	from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
	from .tokenization_lxmert import LxmertTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_lxmert_fast import LxmertTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_lxmert import (
		    LxmertEncoder,
		    LxmertForPreTraining,
		    LxmertForQuestionAnswering,
		    LxmertModel,
		    LxmertPreTrainedModel,
		    LxmertVisualFeatureEncoder,
		    LxmertXLayer,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_lxmert import (
		    TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFLxmertForPreTraining,
		    TFLxmertMainLayer,
		    TFLxmertModel,
		    TFLxmertPreTrainedModel,
		    TFLxmertVisualFeatureEncoder,
		)

else:
	import sys

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






