


"""simple docstring"""






import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor





class      lowerCamelCase__   (     unittest.TestCase				):







					"""simple docstring"""


					def __init__(       self    : Union[str, Any] ,       UpperCamelCase    : str ,       UpperCamelCase    : str=7 ,       UpperCamelCase    : Any=3 ,       UpperCamelCase    : Dict=18 ,       UpperCamelCase    : Dict=30 ,       UpperCamelCase    : Optional[Any]=400 ,       UpperCamelCase    : Union[str, Any]=True ,       UpperCamelCase    : Dict=None ,       UpperCamelCase    : int=True ,       UpperCamelCase    : str=False ,       UpperCamelCase    : int=True ,       UpperCamelCase    : Any=True ,       UpperCamelCase    : Optional[Any]=[0.5, 0.5, 0.5] ,       UpperCamelCase    : List[Any]=[0.5, 0.5, 0.5] ,       ):
												'''simple docstring'''






												__UpperCAmelCase   :						Dict      							=					parent
												__UpperCAmelCase   :						Any      							=					batch_size
												__UpperCAmelCase   :						str      							=					num_channels
												__UpperCAmelCase   :						Dict      							=					image_size
												__UpperCAmelCase   :						Any      							=					min_resolution
												__UpperCAmelCase   :						str      							=					max_resolution
												__UpperCAmelCase   :						Any      							=					do_resize
												__UpperCAmelCase   :						Tuple      							=					size if size is not None else {"""height""": 18, """width""": 20}
												__UpperCAmelCase   :						Union[str, Any]      							=					do_thumbnail
												__UpperCAmelCase   :						List[Any]      							=					do_align_axis
												__UpperCAmelCase   :						Any      							=					do_pad
												__UpperCAmelCase   :						Any      							=					do_normalize
												__UpperCAmelCase   :						List[Any]      							=					image_mean
												__UpperCAmelCase   :						Union[str, Any]      							=					image_std






					def lowerCamelCase__							(       self    : Optional[Any]  ):
												'''simple docstring'''






												return {
												    "do_resize": self.do_resize,
												    "size": self.size,
												    "do_thumbnail": self.do_thumbnail,
												    "do_align_long_axis": self.do_align_axis,
												    "do_pad": self.do_pad,
												    "do_normalize": self.do_normalize,
												    "image_mean": self.image_mean,
												    "image_std": self.image_std,
												}






@require_torch
@require_vision
class      lowerCamelCase__   (     A     ,    unittest.TestCase				):







					"""simple docstring"""


					__a	       =							DonutImageProcessor if is_vision_available() else None






					def lowerCamelCase__							(       self    : Optional[int]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[int]      							=					DonutImageProcessingTester(self  )






					@property
					def lowerCamelCase__							(       self    : Optional[int]  ):
												'''simple docstring'''






												return self.image_processor_tester.prepare_image_processor_dict()






					def lowerCamelCase__							(       self    : Optional[int]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[Any]      							=					self.image_processing_class(**self.image_processor_dict  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_resize"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """size"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_thumbnail"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_align_long_axis"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_pad"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_normalize"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """image_mean"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """image_std"""  )  )






					def lowerCamelCase__							(       self    : Any  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[Any]      							=					self.image_processing_class.from_dict(self.image_processor_dict  )
												self.assertEqual(image_processor.size ,       {"""height""": 18, """width""": 20}  )

												__UpperCAmelCase   :						Optional[Any]      							=					self.image_processing_class.from_dict(self.image_processor_dict ,       size=42  )
												self.assertEqual(image_processor.size ,       {"""height""": 42, """width""": 42}  )

												# Previous config had dimensions in (width, height) order
												__UpperCAmelCase   :						Tuple      							=					self.image_processing_class.from_dict(self.image_processor_dict ,       size=(42, 84)  )
												self.assertEqual(image_processor.size ,       {"""height""": 84, """width""": 42}  )






					def lowerCamelCase__							(       self    : Any  ):
												'''simple docstring'''






												pass






					@is_flaky()
					def lowerCamelCase__							(       self    : Tuple  ):
												'''simple docstring'''






												__UpperCAmelCase   :						List[str]      							=					self.image_processing_class(**self.image_processor_dict  )
												# create random PIL images
												__UpperCAmelCase   :						Optional[int]      							=					prepare_image_inputs(self.image_processor_tester ,       equal_resolution=UpperCamelCase  )
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase ,       Image.Image  )

												# Test not batched input
												__UpperCAmelCase   :						Tuple      							=					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.size["""height"""],
												        self.image_processor_tester.size["""width"""],
												    ) ,       )

												# Test batched
												__UpperCAmelCase   :						Dict      							=					image_processing(UpperCamelCase ,       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.size["""height"""],
												        self.image_processor_tester.size["""width"""],
												    ) ,       )






					@is_flaky()
					def lowerCamelCase__							(       self    : Optional[Any]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Dict      							=					self.image_processing_class(**self.image_processor_dict  )
												# create random numpy tensors
												__UpperCAmelCase   :						int      							=					prepare_image_inputs(self.image_processor_tester ,       equal_resolution=UpperCamelCase ,       numpify=UpperCamelCase  )
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase ,       np.ndarray  )

												# Test not batched input
												__UpperCAmelCase   :						List[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.size["""height"""],
												        self.image_processor_tester.size["""width"""],
												    ) ,       )

												# Test batched
												__UpperCAmelCase   :						List[str]      							=					image_processing(UpperCamelCase ,       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.size["""height"""],
												        self.image_processor_tester.size["""width"""],
												    ) ,       )






					@is_flaky()
					def lowerCamelCase__							(       self    : int  ):
												'''simple docstring'''






												__UpperCAmelCase   :						int      							=					self.image_processing_class(**self.image_processor_dict  )
												# create random PyTorch tensors
												__UpperCAmelCase   :						Tuple      							=					prepare_image_inputs(self.image_processor_tester ,       equal_resolution=UpperCamelCase ,       torchify=UpperCamelCase  )
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase ,       torch.Tensor  )

												# Test not batched input
												__UpperCAmelCase   :						Optional[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.size["""height"""],
												        self.image_processor_tester.size["""width"""],
												    ) ,       )

												# Test batched
												__UpperCAmelCase   :						int      							=					image_processing(UpperCamelCase ,       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.size["""height"""],
												        self.image_processor_tester.size["""width"""],
												    ) ,       )




"""simple docstring"""






# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


UpperCAmelCase    :     Union[str, Any]   						=		{'configuration_mra': ['MRA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MraConfig']}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase    :     int   						=		[
							    'MRA_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'MraForMaskedLM',
							    'MraForMultipleChoice',
							    'MraForQuestionAnswering',
							    'MraForSequenceClassification',
							    'MraForTokenClassification',
							    'MraLayer',
							    'MraModel',
							    'MraPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_mra import MRA_PRETRAINED_CONFIG_ARCHIVE_MAP, MraConfig

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_mra import (
														    MRA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    MraForMaskedLM,
														    MraForMultipleChoice,
														    MraForQuestionAnswering,
														    MraForSequenceClassification,
														    MraForTokenClassification,
														    MraLayer,
														    MraModel,
														    MraPreTrainedModel,
														)
else:
							import sys

							UpperCAmelCase    :     Tuple   						=		_LazyModule(__name__, globals()['__file__'], _import_structure)
