

"""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_video_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import VivitImageProcessor
class      _UpperCAmelCase   (							unittest.TestCase       ):



	def __init__(  self     :       Optional[Any]			,    _lowercase     :       List[str]			,    _lowercase     :       int=7			,    _lowercase     :       Union[str, Any]=3			,    _lowercase     :       List[str]=10			,    _lowercase     :       Optional[Any]=18			,    _lowercase     :       int=30			,    _lowercase     :       Optional[int]=4_00			,    _lowercase     :       List[Any]=True			,    _lowercase     :       int=None			,    _lowercase     :       List[Any]=True			,    _lowercase     :       List[Any]=[0.5, 0.5, 0.5]			,    _lowercase     :       Tuple=[0.5, 0.5, 0.5]			,    _lowercase     :       Tuple=None			,    ):
		__UpperCAmelCase      		= size if size is not None else {'''shortest_edge''': 18}
		__UpperCAmelCase      		= crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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



	def        a  (  self     :       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      _UpperCAmelCase   (							_lowerCAmelCase		,    unittest.TestCase       ):
	a__		: List[Any]					=					VivitImageProcessor if is_vision_available() else None



	def        a  (  self     :       List[Any]						):
		__UpperCAmelCase      		= VivitImageProcessingTester(self						)



	@property
	def        a  (  self     :       List[Any]						):
		return self.image_processor_tester.prepare_image_processor_dict()



	def        a  (  self     :       Optional[int]						):
		__UpperCAmelCase      		= self.image_processing_class(**self.image_processor_dict						)
		self.assertTrue(hasattr(_lowercase			,    '''image_mean'''						)						)
		self.assertTrue(hasattr(_lowercase			,    '''image_std'''						)						)
		self.assertTrue(hasattr(_lowercase			,    '''do_normalize'''						)						)
		self.assertTrue(hasattr(_lowercase			,    '''do_resize'''						)						)
		self.assertTrue(hasattr(_lowercase			,    '''do_center_crop'''						)						)
		self.assertTrue(hasattr(_lowercase			,    '''size'''						)						)



	def        a  (  self     :       int						):
		__UpperCAmelCase      		= 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      		= 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     :       str						):
		# Initialize image_processing
		__UpperCAmelCase      		= self.image_processing_class(**self.image_processor_dict						)
		# create random PIL videos
		__UpperCAmelCase      		= prepare_video_inputs(self.image_processor_tester			,    equal_resolution=_lowercase						)
		for video in video_inputs:
			self.assertIsInstance(_lowercase			,    _lowercase						)
			self.assertIsInstance(video[0]			,    Image.Image						)

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

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

		# Test not batched input
		__UpperCAmelCase      		= 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      		= image_processing(_lowercase			,    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_torch_available


A_			:					Tuple    			=     {
    'configuration_xlm': ['XLM_PRETRAINED_CONFIG_ARCHIVE_MAP', 'XLMConfig', 'XLMOnnxConfig'],
    'tokenization_xlm': ['XLMTokenizer'],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A_			:					Dict    			=     [
	    'XLM_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'XLMForMultipleChoice',
	    'XLMForQuestionAnswering',
	    'XLMForQuestionAnsweringSimple',
	    'XLMForSequenceClassification',
	    'XLMForTokenClassification',
	    'XLMModel',
	    'XLMPreTrainedModel',
	    'XLMWithLMHeadModel',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A_			:					str    			=     [
	    'TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'TFXLMForMultipleChoice',
	    'TFXLMForQuestionAnsweringSimple',
	    'TFXLMForSequenceClassification',
	    'TFXLMForTokenClassification',
	    'TFXLMMainLayer',
	    'TFXLMModel',
	    'TFXLMPreTrainedModel',
	    'TFXLMWithLMHeadModel',
	]


if TYPE_CHECKING:
	from .configuration_xlm import XLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMConfig, XLMOnnxConfig
	from .tokenization_xlm import XLMTokenizer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_xlm import (
		    XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
		    XLMForMultipleChoice,
		    XLMForQuestionAnswering,
		    XLMForQuestionAnsweringSimple,
		    XLMForSequenceClassification,
		    XLMForTokenClassification,
		    XLMModel,
		    XLMPreTrainedModel,
		    XLMWithLMHeadModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_xlm import (
		    TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFXLMForMultipleChoice,
		    TFXLMForQuestionAnsweringSimple,
		    TFXLMForSequenceClassification,
		    TFXLMForTokenClassification,
		    TFXLMMainLayer,
		    TFXLMModel,
		    TFXLMPreTrainedModel,
		    TFXLMWithLMHeadModel,
		)

else:
	import sys

	A_			:					Tuple    			=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



