


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





class      __A     (unittest.TestCase):





							'''simple docstring'''

							def __init__(				self							:      Any		,       UpperCAmelCase_							:      Dict		,       UpperCAmelCase_							:      Any=7		,       UpperCAmelCase_							:      int=3		,       UpperCAmelCase_							:      List[Any]=18		,       UpperCAmelCase_							:      str=30		,       UpperCAmelCase_							:      Tuple=400		,       UpperCAmelCase_							:      Optional[Any]=True		,       UpperCAmelCase_							:      str=None		,       UpperCAmelCase_							:      str=True		,       UpperCAmelCase_							:      List[str]=None		,       UpperCAmelCase_							:      int=True		,       )					->List[str]:



														"""simple docstring"""



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



							def 		lowerCAmelCase       (				self							:      Any       )					->List[str]:



														"""simple docstring"""



														return {
														    "do_resize": self.do_resize,
														    "size": self.size,
														    "do_center_crop": self.do_center_crop,
														    "crop_size": self.crop_size,
														    "do_flip_channel_order": self.do_flip_channel_order,
														}





@require_torch
@require_vision
class      __A     (snake_case__						,		unittest.TestCase):





							'''simple docstring'''

							__lowercase:		Tuple							      =    MobileViTImageProcessor if is_vision_available() else None



							def 		lowerCAmelCase       (				self							:      int       )					->Dict:



														"""simple docstring"""



														snake_case_           =		MobileViTImageProcessingTester(self       )



							@property
							def 		lowerCAmelCase       (				self							:      str       )					->Optional[Any]:



														"""simple docstring"""



														return self.image_processor_tester.prepare_image_processor_dict()



							def 		lowerCAmelCase       (				self							:      int       )					->Union[str, Any]:



														"""simple docstring"""



														snake_case_           =		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_		,       """center_crop"""       )       )
														self.assertTrue(hasattr(UpperCAmelCase_		,       """do_flip_channel_order"""       )       )



							def 		lowerCAmelCase       (				self							:      Any       )					->int:



														"""simple docstring"""



														snake_case_           =		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}       )

														snake_case_           =		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 		lowerCAmelCase       (				self							:      Union[str, Any]       )					->Dict:



														"""simple docstring"""



														pass



							def 		lowerCAmelCase       (				self							:      Union[str, Any]       )					->Optional[int]:



														"""simple docstring"""



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

														# Test not batched input
														snake_case_           =		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
														snake_case_           =		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 		lowerCAmelCase       (				self							:      Tuple       )					->int:



														"""simple docstring"""



														snake_case_           =		self.image_processing_class(**self.image_processor_dict       )
														# create random numpy tensors
														snake_case_           =		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
														snake_case_           =		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
														snake_case_           =		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 		lowerCAmelCase       (				self							:      str       )					->str:



														"""simple docstring"""



														snake_case_           =		self.image_processing_class(**self.image_processor_dict       )
														# create random PyTorch tensors
														snake_case_           =		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
														snake_case_           =		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
														snake_case_           =		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"""
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__SCREAMING_SNAKE_CASE							:    Optional[Any]		=    {
    'configuration_megatron_bert': ['MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MegatronBertConfig'],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__SCREAMING_SNAKE_CASE							:    Tuple		=    [
				    'MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'MegatronBertForCausalLM',
				    'MegatronBertForMaskedLM',
				    'MegatronBertForMultipleChoice',
				    'MegatronBertForNextSentencePrediction',
				    'MegatronBertForPreTraining',
				    'MegatronBertForQuestionAnswering',
				    'MegatronBertForSequenceClassification',
				    'MegatronBertForTokenClassification',
				    'MegatronBertModel',
				    'MegatronBertPreTrainedModel',
				]

if TYPE_CHECKING:
				from .configuration_megatron_bert import MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, MegatronBertConfig

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_megatron_bert import (
								    MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
								    MegatronBertForCausalLM,
								    MegatronBertForMaskedLM,
								    MegatronBertForMultipleChoice,
								    MegatronBertForNextSentencePrediction,
								    MegatronBertForPreTraining,
								    MegatronBertForQuestionAnswering,
								    MegatronBertForSequenceClassification,
								    MegatronBertForTokenClassification,
								    MegatronBertModel,
								    MegatronBertPreTrainedModel,
								)

else:
				import sys

				__SCREAMING_SNAKE_CASE							:    int		=    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



