



'''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_image_inputs


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import PoolFormerImageProcessor


class      __lowerCAmelCase     (		unittest.TestCase      ):
					"""simple docstring"""






					def __init__(     self					:       List[str]				,					_snake_case					:       Optional[Any]				,					_snake_case					:       int=7				,					_snake_case					:       Dict=3				,					_snake_case					:       Any=30				,					_snake_case					:       Any=4_00				,					_snake_case					:       List[str]=True				,					_snake_case					:       Tuple=None				,					_snake_case					:       Union[str, Any]=0.9				,					_snake_case					:       Any=None				,					_snake_case					:       int=True				,					_snake_case					:       Optional[Any]=[0.5, 0.5, 0.5]				,					_snake_case					:       List[str]=[0.5, 0.5, 0.5]				,					):






								"""simple docstring"""


								A__       =    size if size is not None else {"""shortest_edge""": 30}
								A__       =    crop_size if crop_size is not None else {"""height""": 30, """width""": 30}
								A__       =    parent
								A__       =    batch_size
								A__       =    num_channels
								A__       =    min_resolution
								A__       =    max_resolution
								A__       =    do_resize_and_center_crop
								A__       =    size
								A__       =    crop_pct
								A__       =    crop_size
								A__       =    do_normalize
								A__       =    image_mean
								A__       =    image_std



					def     _a							(     self					:       Optional[Any]					):






								"""simple docstring"""


								return {
								    "size": self.size,
								    "do_resize_and_center_crop": self.do_resize_and_center_crop,
								    "crop_pct": self.crop_pct,
								    "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     (		UpperCAmelCase_							,     unittest.TestCase      ):
					"""simple docstring"""






					A__				:		Tuple			       =    PoolFormerImageProcessor if is_vision_available() else None



					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								A__       =    PoolFormerImageProcessingTester(self					)



					@property
					def     _a							(     self					:       Dict					):






								"""simple docstring"""


								return self.image_processor_tester.prepare_image_processor_dict()



					def     _a							(     self					:       Tuple					):






								"""simple docstring"""


								A__       =    self.image_processing_class(**self.image_processor_dict					)
								self.assertTrue(hasattr(A__				,					'do_resize_and_center_crop'					)					)
								self.assertTrue(hasattr(A__				,					'size'					)					)
								self.assertTrue(hasattr(A__				,					'crop_pct'					)					)
								self.assertTrue(hasattr(A__				,					'do_normalize'					)					)
								self.assertTrue(hasattr(A__				,					'image_mean'					)					)
								self.assertTrue(hasattr(A__				,					'image_std'					)					)



					def     _a							(     self					:       Tuple					):






								"""simple docstring"""


								A__       =    self.image_processing_class.from_dict(self.image_processor_dict					)
								self.assertEqual(image_processor.size				,					{'shortest_edge': 30}					)
								self.assertEqual(image_processor.crop_size				,					{'height': 30, 'width': 30}					)

								A__       =    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					:       int					):






								"""simple docstring"""


								pass



					def     _a							(     self					:       List[str]					):






								"""simple docstring"""


								A__       =    self.image_processing_class(**self.image_processor_dict					)
								# create random PIL images
								A__       =    prepare_image_inputs(self.image_processor_tester				,					equal_resolution=A__					)
								for image in image_inputs:
											self.assertIsInstance(A__				,					Image.Image					)

								# Test not batched input
								A__       =    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
								A__       =    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     _a							(     self					:       Any					):






								"""simple docstring"""


								A__       =    self.image_processing_class(**self.image_processor_dict					)
								# create random numpy tensors
								A__       =    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
								A__       =    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
								A__       =    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     _a							(     self					:       Dict					):






								"""simple docstring"""


								A__       =    self.image_processing_class(**self.image_processor_dict					)
								# create random PyTorch tensors
								A__       =    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
								A__       =    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
								A__       =    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,
)


SCREAMING_SNAKE_CASE__       =      {
    '''configuration_xlm_roberta''': [
        '''XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XLMRobertaConfig''',
        '''XLMRobertaOnnxConfig''',
    ],
}

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

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

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       =      [
							    '''XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''XLMRobertaForCausalLM''',
							    '''XLMRobertaForMaskedLM''',
							    '''XLMRobertaForMultipleChoice''',
							    '''XLMRobertaForQuestionAnswering''',
							    '''XLMRobertaForSequenceClassification''',
							    '''XLMRobertaForTokenClassification''',
							    '''XLMRobertaModel''',
							    '''XLMRobertaPreTrainedModel''',
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       =      [
							    '''TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''TFXLMRobertaForCausalLM''',
							    '''TFXLMRobertaForMaskedLM''',
							    '''TFXLMRobertaForMultipleChoice''',
							    '''TFXLMRobertaForQuestionAnswering''',
							    '''TFXLMRobertaForSequenceClassification''',
							    '''TFXLMRobertaForTokenClassification''',
							    '''TFXLMRobertaModel''',
							    '''TFXLMRobertaPreTrainedModel''',
							]

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       =      [
							    '''FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''FlaxXLMRobertaForMaskedLM''',
							    '''FlaxXLMRobertaForCausalLM''',
							    '''FlaxXLMRobertaForMultipleChoice''',
							    '''FlaxXLMRobertaForQuestionAnswering''',
							    '''FlaxXLMRobertaForSequenceClassification''',
							    '''FlaxXLMRobertaForTokenClassification''',
							    '''FlaxXLMRobertaModel''',
							    '''FlaxXLMRobertaPreTrainedModel''',
							]

if TYPE_CHECKING:
							from .configuration_xlm_roberta import (
							    XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    XLMRobertaConfig,
							    XLMRobertaOnnxConfig,
							)

							try:
														if not is_sentencepiece_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_xlm_roberta import XLMRobertaTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_xlm_roberta_fast import XLMRobertaTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_xlm_roberta import (
														    XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    XLMRobertaForCausalLM,
														    XLMRobertaForMaskedLM,
														    XLMRobertaForMultipleChoice,
														    XLMRobertaForQuestionAnswering,
														    XLMRobertaForSequenceClassification,
														    XLMRobertaForTokenClassification,
														    XLMRobertaModel,
														    XLMRobertaPreTrainedModel,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_xlm_roberta import (
														    TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFXLMRobertaForCausalLM,
														    TFXLMRobertaForMaskedLM,
														    TFXLMRobertaForMultipleChoice,
														    TFXLMRobertaForQuestionAnswering,
														    TFXLMRobertaForSequenceClassification,
														    TFXLMRobertaForTokenClassification,
														    TFXLMRobertaModel,
														    TFXLMRobertaPreTrainedModel,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_xlm_roberta import (
														    FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    FlaxXLMRobertaForCausalLM,
														    FlaxXLMRobertaForMaskedLM,
														    FlaxXLMRobertaForMultipleChoice,
														    FlaxXLMRobertaForQuestionAnswering,
														    FlaxXLMRobertaForSequenceClassification,
														    FlaxXLMRobertaForTokenClassification,
														    FlaxXLMRobertaModel,
														    FlaxXLMRobertaPreTrainedModel,
														)

else:
							import sys

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




