


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 DeiTImageProcessor





class    lowerCAmelCase__				(			unittest.TestCase       ):






						"""simple docstring"""




						def __init__(   self				,							a_				,							a_=7				,							a_=3				,							a_=18				,							a_=30				,							a_=400				,							a_=True				,							a_=None				,							a_=True				,							a_=None				,							a_=True				,							a_=[0.5, 0.5, 0.5]				,							a_=[0.5, 0.5, 0.5]				,							):
							lowerCamelCase_			:							Optional[Any]      =       size if size is not None else {"height": 20, "width": 20}
							lowerCamelCase_			:							Any      =       crop_size if crop_size is not None else {"height": 18, "width": 18}

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




						def 					_UpperCamelCase			(   self     ):
							return {
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_center_crop": self.do_center_crop,
							    "crop_size": self.crop_size,
							    "do_normalize": self.do_normalize,
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							}





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






						"""simple docstring"""
						__UpperCAmelCase   :		Tuple  					=	DeiTImageProcessor if is_vision_available() else None
						__UpperCAmelCase   :		int  					=	True




						def 					_UpperCamelCase			(   self     ):
							lowerCamelCase_			:							Optional[int]      =       DeiTImageProcessingTester(self     )




						@property
						def 					_UpperCamelCase			(   self     ):
							return self.image_processor_tester.prepare_image_processor_dict()




						def 					_UpperCamelCase			(   self     ):
							lowerCamelCase_			:							Union[str, Any]      =       self.image_processing_class(**self.image_processor_dict     )
							self.assertTrue(hasattr(a_				,							"do_resize"     )     )
							self.assertTrue(hasattr(a_				,							"size"     )     )
							self.assertTrue(hasattr(a_				,							"do_center_crop"     )     )
							self.assertTrue(hasattr(a_				,							"center_crop"     )     )
							self.assertTrue(hasattr(a_				,							"do_normalize"     )     )
							self.assertTrue(hasattr(a_				,							"image_mean"     )     )
							self.assertTrue(hasattr(a_				,							"image_std"     )     )




						def 					_UpperCamelCase			(   self     ):
							lowerCamelCase_			:							int      =       self.image_processing_class.from_dict(self.image_processor_dict     )
							self.assertEqual(image_processor.size				,							{"height": 20, "width": 20}     )
							self.assertEqual(image_processor.crop_size				,							{"height": 18, "width": 18}     )

							lowerCamelCase_			:							str      =       self.image_processing_class.from_dict(self.image_processor_dict				,							size=42				,							crop_size=84     )
							self.assertEqual(image_processor.size				,							{"height": 42, "width": 42}     )
							self.assertEqual(image_processor.crop_size				,							{"height": 84, "width": 84}     )




						def 					_UpperCamelCase			(   self     ):
							pass




						def 					_UpperCamelCase			(   self     ):
							lowerCamelCase_			:							Union[str, Any]      =       self.image_processing_class(**self.image_processor_dict     )
							# create random PIL images
							lowerCamelCase_			:							Any      =       prepare_image_inputs(self.image_processor_tester				,							equal_resolution=a_     )
							for image in image_inputs:
								self.assertIsInstance(a_				,							Image.Image     )

							# Test not batched input
							lowerCamelCase_			:							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
							lowerCamelCase_			:							List[str]      =       image_processing(a_				,							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     ):
							lowerCamelCase_			:							Dict      =       self.image_processing_class(**self.image_processor_dict     )
							# create random numpy tensors
							lowerCamelCase_			:							Optional[Any]      =       prepare_image_inputs(self.image_processor_tester				,							equal_resolution=a_				,							numpify=a_     )
							for image in image_inputs:
								self.assertIsInstance(a_				,							np.ndarray     )

							# Test not batched input
							lowerCamelCase_			:							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
							lowerCamelCase_			:							int      =       image_processing(a_				,							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     ):
							lowerCamelCase_			:							Optional[int]      =       self.image_processing_class(**self.image_processor_dict     )
							# create random PyTorch tensors
							lowerCamelCase_			:							List[str]      =       prepare_image_inputs(self.image_processor_tester				,							equal_resolution=a_				,							torchify=a_     )
							for image in image_inputs:
								self.assertIsInstance(a_				,							torch.Tensor     )

							# Test not batched input
							lowerCamelCase_			:							List[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
							lowerCamelCase_			:							Union[str, Any]      =       image_processing(a_				,							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"],
							    )				,							)





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__magic_name__       					=      {
    '''configuration_big_bird''': ['''BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''BigBirdConfig''', '''BigBirdOnnxConfig'''],
}

try:
							if not is_sentencepiece_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__magic_name__       					=      ['''BigBirdTokenizer''']

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__magic_name__       					=      ['''BigBirdTokenizerFast''']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__magic_name__       					=      [
							    '''BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''BigBirdForCausalLM''',
							    '''BigBirdForMaskedLM''',
							    '''BigBirdForMultipleChoice''',
							    '''BigBirdForPreTraining''',
							    '''BigBirdForQuestionAnswering''',
							    '''BigBirdForSequenceClassification''',
							    '''BigBirdForTokenClassification''',
							    '''BigBirdLayer''',
							    '''BigBirdModel''',
							    '''BigBirdPreTrainedModel''',
							    '''load_tf_weights_in_big_bird''',
							]

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__magic_name__       					=      [
							    '''FlaxBigBirdForCausalLM''',
							    '''FlaxBigBirdForMaskedLM''',
							    '''FlaxBigBirdForMultipleChoice''',
							    '''FlaxBigBirdForPreTraining''',
							    '''FlaxBigBirdForQuestionAnswering''',
							    '''FlaxBigBirdForSequenceClassification''',
							    '''FlaxBigBirdForTokenClassification''',
							    '''FlaxBigBirdModel''',
							    '''FlaxBigBirdPreTrainedModel''',
							]

if TYPE_CHECKING:
							from .configuration_big_bird import BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP, BigBirdConfig, BigBirdOnnxConfig

							try:
														if not is_sentencepiece_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_big_bird import BigBirdTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_big_bird_fast import BigBirdTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_big_bird import (
														    BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST,
														    BigBirdForCausalLM,
														    BigBirdForMaskedLM,
														    BigBirdForMultipleChoice,
														    BigBirdForPreTraining,
														    BigBirdForQuestionAnswering,
														    BigBirdForSequenceClassification,
														    BigBirdForTokenClassification,
														    BigBirdLayer,
														    BigBirdModel,
														    BigBirdPreTrainedModel,
														    load_tf_weights_in_big_bird,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_big_bird import (
														    FlaxBigBirdForCausalLM,
														    FlaxBigBirdForMaskedLM,
														    FlaxBigBirdForMultipleChoice,
														    FlaxBigBirdForPreTraining,
														    FlaxBigBirdForQuestionAnswering,
														    FlaxBigBirdForSequenceClassification,
														    FlaxBigBirdForTokenClassification,
														    FlaxBigBirdModel,
														    FlaxBigBirdPreTrainedModel,
														)

else:
							import sys

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

