

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



class 					a						(       unittest.TestCase				):



				"""simple docstring"""



				def __init__(     self: Any    ,						UpperCamelCase: str    ,						UpperCamelCase: Union[str, Any]=7    ,						UpperCamelCase: Optional[Any]=3    ,						UpperCamelCase: int=18    ,						UpperCamelCase: int=30    ,						UpperCamelCase: List[str]=4_00    ,						UpperCamelCase: Optional[int]=True    ,						UpperCamelCase: str=None    ,						UpperCamelCase: str=True    ,						UpperCamelCase: Union[str, Any]=None    ,						):






									"""simple docstring"""


									A__										=  size if size is not None else {"""shortest_edge""": 20}
									A__										=  crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
									A__										=  parent
									A__										=  batch_size
									A__										=  num_channels
									A__										=  image_size
									A__										=  min_resolution
									A__										=  max_resolution
									A__										=  do_resize
									A__										=  size
									A__										=  do_center_crop
									A__										=  crop_size





				def 				UpperCamelCase	(     self: Union[str, Any]       ):






									"""simple docstring"""


									return {
									    "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 					a						(       _lowerCamelCase,	unittest.TestCase				):



				"""simple docstring"""



				UpperCAmelCase						 =					MobileNetVaImageProcessor if is_vision_available() else None

				def 				UpperCamelCase	(     self: Any       ):






									"""simple docstring"""


									A__										=  MobileNetVaImageProcessingTester(self       )

				@property
				def 				UpperCamelCase	(     self: List[Any]       ):






									"""simple docstring"""


									return self.image_processor_tester.prepare_image_processor_dict()

				def 				UpperCamelCase	(     self: Optional[Any]       ):






									"""simple docstring"""


									A__										=  self.image_processing_class(**self.image_processor_dict       )
									self.assertTrue(hasattr(UpperCamelCase    ,						"""do_resize"""       )       )
									self.assertTrue(hasattr(UpperCamelCase    ,						"""size"""       )       )
									self.assertTrue(hasattr(UpperCamelCase    ,						"""do_center_crop"""       )       )
									self.assertTrue(hasattr(UpperCamelCase    ,						"""crop_size"""       )       )

				def 				UpperCamelCase	(     self: Optional[int]       ):






									"""simple docstring"""


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

									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 				UpperCamelCase	(     self: Dict       ):






									"""simple docstring"""


									pass

				def 				UpperCamelCase	(     self: Any       ):






									"""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=UpperCamelCase       )
									for image in image_inputs:
														self.assertIsInstance(UpperCamelCase    ,						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(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.crop_size["""height"""],
									        self.image_processor_tester.crop_size["""width"""],
									    )    ,						)

				def 				UpperCamelCase	(     self: Optional[int]       ):






									"""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=UpperCamelCase    ,						numpify=UpperCamelCase       )
									for image in image_inputs:
														self.assertIsInstance(UpperCamelCase    ,						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(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.crop_size["""height"""],
									        self.image_processor_tester.crop_size["""width"""],
									    )    ,						)





				def 				UpperCamelCase	(     self: Any       ):






									"""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=UpperCamelCase    ,						torchify=UpperCamelCase       )
									for image in image_inputs:
														self.assertIsInstance(UpperCamelCase    ,						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(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.crop_size["""height"""],
									        self.image_processor_tester.crop_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


SCREAMING_SNAKE_CASE_					:	List[str]							  =						{'configuration_mra': ['MRA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MraConfig']}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE_					:	List[Any]							  =						[
     '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

 SCREAMING_SNAKE_CASE_					:	List[str]							  =						_LazyModule(__name__, globals()['__file__'], _import_structure)






