


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 TvltImageProcessor
def 				UpperCamelCase_	(					__snake_case      :    List[Any]						,      __snake_case      :    Optional[int]=10						,      __snake_case      :    Tuple=10						,      __snake_case      :    Union[str, Any]=False						,      __snake_case      :    List[Any]=False  )->   Optional[Any]:




						'''simple docstring'''
						__magic_name__					=      []
						for i in range(image_processor_tester.num_frames  ):
												video.append(np.random.randint(2_55						,      size=(image_processor_tester.num_channels, width, height)						,      dtype=np.uinta  )  )

						if not numpify and not torchify:
												# PIL expects the channel dimension as last dimension
												__magic_name__					=      [Image.fromarray(np.moveaxis(__snake_case						,      0						,      -1  )  ) for frame in video]

						if torchify:
												__magic_name__					=      [torch.from_numpy(__snake_case  ) for frame in video]

						return video
def 				UpperCamelCase_	(					__snake_case      :    Optional[Any]						,      __snake_case      :    str=False						,      __snake_case      :    List[Any]=False						,      __snake_case      :    Any=False  )->   Dict:




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

						__magic_name__					=      []
						for i in range(image_processor_tester.batch_size  ):
												if equal_resolution:
																		__magic_name__					=      __magic_name__					=      image_processor_tester.max_resolution
												else:
																		__magic_name__		,      __magic_name__					=      np.random.choice(
																		    np.arange(image_processor_tester.min_resolution						,      image_processor_tester.max_resolution  )						,      2  )
																		__magic_name__					=      prepare_video(
																		    image_processor_tester=__snake_case						,      width=__snake_case						,      height=__snake_case						,      numpify=__snake_case						,      torchify=__snake_case						,      )
												video_inputs.append(__snake_case  )

						return video_inputs

class      __snake_case				(   unittest.TestCase):
					def __init__(						self       :						List[Any]	,      _lowerCAmelCase       :						Union[str, Any]	,      _lowerCAmelCase       :						int=7	,      _lowerCAmelCase       :						Union[str, Any]=3	,      _lowerCAmelCase       :						List[str]=4	,      _lowerCAmelCase       :						Optional[int]=1_8	,      _lowerCAmelCase       :						List[str]=3_0	,      _lowerCAmelCase       :						Optional[int]=4_0_0	,      _lowerCAmelCase       :						Any=True	,      _lowerCAmelCase       :						Tuple=None	,      _lowerCAmelCase       :						List[str]=True	,      _lowerCAmelCase       :						str=[0.5, 0.5, 0.5]	,      _lowerCAmelCase       :						str=[0.5, 0.5, 0.5]	,      _lowerCAmelCase       :						Tuple=True	,      _lowerCAmelCase       :						Any=None	,      )							->					List[Any]:



											'''simple docstring'''





											__magic_name__					=      size if size is not None else {'shortest_edge': 1_8}
											__magic_name__					=      crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}

											__magic_name__					=      parent
											__magic_name__					=      batch_size
											__magic_name__					=      num_channels
											__magic_name__					=      num_frames
											__magic_name__					=      image_size
											__magic_name__					=      min_resolution
											__magic_name__					=      max_resolution
											__magic_name__					=      do_resize
											__magic_name__					=      size
											__magic_name__					=      do_normalize
											__magic_name__					=      image_mean
											__magic_name__					=      image_std
											__magic_name__					=      do_center_crop
											__magic_name__					=      crop_size







					def 	a			(						self       :						str  )							->					List[Any]:



											'''simple docstring'''





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







@require_torch
@require_vision
class      __snake_case				(   _UpperCAmelCase	,      unittest.TestCase):
					SCREAMING_SNAKE_CASE_		:       Dict								=			TvltImageProcessor if is_vision_available() else None
					def 	a			(						self       :						List[str]  )							->					Optional[int]:



											'''simple docstring'''





											__magic_name__					=      TvltImageProcessorTester(self  )
					@property
					def 	a			(						self       :						List[Any]  )							->					Tuple:



											'''simple docstring'''





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



											'''simple docstring'''





											__magic_name__					=      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 	a			(						self       :						Dict  )							->					Optional[int]:



											'''simple docstring'''





											__magic_name__					=      self.image_processing_class(**self.image_processor_dict  )
											# create random PIL videos
											__magic_name__					=      prepare_video_inputs(self.image_processor_tester	,      equal_resolution=_lowerCAmelCase  )
											for video in video_inputs:
																	self.assertIsInstance(_lowerCAmelCase	,      _lowerCAmelCase  )
																	self.assertIsInstance(video[0]	,      Image.Image  )

											# Test not batched input
											__magic_name__					=      image_processor(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
											__magic_name__					=      image_processor(_lowerCAmelCase	,      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 	a			(						self       :						List[Any]  )							->					int:



											'''simple docstring'''





											__magic_name__					=      self.image_processing_class(**self.image_processor_dict  )
											# create random numpy tensors
											__magic_name__					=      prepare_video_inputs(self.image_processor_tester	,      equal_resolution=_lowerCAmelCase	,      numpify=_lowerCAmelCase  )
											for video in video_inputs:
																	self.assertIsInstance(_lowerCAmelCase	,      _lowerCAmelCase  )
																	self.assertIsInstance(video[0]	,      np.ndarray  )

											# Test not batched input
											__magic_name__					=      image_processor(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
											__magic_name__					=      image_processor(_lowerCAmelCase	,      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 	a			(						self       :						int  )							->					int:



											'''simple docstring'''





											__magic_name__					=      self.image_processing_class(**self.image_processor_dict  )
											# create random PyTorch tensors
											__magic_name__					=      prepare_video_inputs(self.image_processor_tester	,      equal_resolution=_lowerCAmelCase	,      torchify=_lowerCAmelCase  )
											for video in video_inputs:
																	self.assertIsInstance(_lowerCAmelCase	,      _lowerCAmelCase  )
																	self.assertIsInstance(video[0]	,      torch.Tensor  )

											# Test not batched input
											__magic_name__					=      image_processor(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
											__magic_name__					=      image_processor(_lowerCAmelCase	,      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,
)


UpperCamelCase			:					Optional[int]         =							{
    '''configuration_dpr''': ['''DPR_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DPRConfig'''],
    '''tokenization_dpr''': [
        '''DPRContextEncoderTokenizer''',
        '''DPRQuestionEncoderTokenizer''',
        '''DPRReaderOutput''',
        '''DPRReaderTokenizer''',
    ],
}


try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCamelCase			:					List[str]         =							[
					    '''DPRContextEncoderTokenizerFast''',
					    '''DPRQuestionEncoderTokenizerFast''',
					    '''DPRReaderTokenizerFast''',
					]

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCamelCase			:					Optional[Any]         =							[
					    '''DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''DPRContextEncoder''',
					    '''DPRPretrainedContextEncoder''',
					    '''DPRPreTrainedModel''',
					    '''DPRPretrainedQuestionEncoder''',
					    '''DPRPretrainedReader''',
					    '''DPRQuestionEncoder''',
					    '''DPRReader''',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCamelCase			:					Optional[int]         =							[
					    '''TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''TFDPRContextEncoder''',
					    '''TFDPRPretrainedContextEncoder''',
					    '''TFDPRPretrainedQuestionEncoder''',
					    '''TFDPRPretrainedReader''',
					    '''TFDPRQuestionEncoder''',
					    '''TFDPRReader''',
					]


if TYPE_CHECKING:
					from .configuration_dpr import DPR_PRETRAINED_CONFIG_ARCHIVE_MAP, DPRConfig
					from .tokenization_dpr import (
					    DPRContextEncoderTokenizer,
					    DPRQuestionEncoderTokenizer,
					    DPRReaderOutput,
					    DPRReaderTokenizer,
					)

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_dpr_fast import (
										    DPRContextEncoderTokenizerFast,
										    DPRQuestionEncoderTokenizerFast,
										    DPRReaderTokenizerFast,
										)

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_dpr import (
										    DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    DPRContextEncoder,
										    DPRPretrainedContextEncoder,
										    DPRPreTrainedModel,
										    DPRPretrainedQuestionEncoder,
										    DPRPretrainedReader,
										    DPRQuestionEncoder,
										    DPRReader,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_dpr import (
										    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFDPRContextEncoder,
										    TFDPRPretrainedContextEncoder,
										    TFDPRPretrainedQuestionEncoder,
										    TFDPRPretrainedReader,
										    TFDPRQuestionEncoder,
										    TFDPRReader,
										)

else:
					import sys

					UpperCamelCase			:					List[Any]         =							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

