






"""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 							_SCREAMING_SNAKE_CASE    (	unittest.TestCase				):





							"""simple docstring"""





							def __init__( self:  Any					,		__A:  Dict					,		__A:  int=7					,		__A:  List[str]=3					,		__A:  List[str]=18					,		__A:  Tuple=30					,		__A:  Union[str, Any]=400					,		__A:  Tuple=True					,		__A:  List[str]=None					,		__A:  Any=True					,		__A:  Tuple=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 			lowercase		( self:  Optional[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 							_SCREAMING_SNAKE_CASE    (	__snake_case							,			unittest.TestCase				):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE     =MobileNetVaImageProcessor if is_vision_available() else None




							def 			lowercase		( self:  Dict     ):

												'''simple docstring'''

												a__ 							=	MobileNetVaImageProcessingTester(self     )




							@property
							def 			lowercase		( self:  Optional[int]     ):

												'''simple docstring'''

												return self.image_processor_tester.prepare_image_processor_dict()




							def 			lowercase		( self:  List[Any]     ):

												'''simple docstring'''

												a__ 							=	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'''     )     )




							def 			lowercase		( self:  List[Any]     ):

												'''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 			lowercase		( self:  Any     ):

												'''simple docstring'''

												pass




							def 			lowercase		( 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 			lowercase		( 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=__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 			lowercase		( self:  Optional[int]     ):

												'''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'''],
												    )					,		)










"""simple docstring"""







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


__a							:						int   							=			{
    'configuration_markuplm': ['MARKUPLM_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MarkupLMConfig'],
    'feature_extraction_markuplm': ['MarkupLMFeatureExtractor'],
    'processing_markuplm': ['MarkupLMProcessor'],
    'tokenization_markuplm': ['MarkupLMTokenizer'],
}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__a							:						List[Any]   							=			['MarkupLMTokenizerFast']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__a							:						List[Any]   							=			[
	    'MARKUPLM_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'MarkupLMForQuestionAnswering',
	    'MarkupLMForSequenceClassification',
	    'MarkupLMForTokenClassification',
	    'MarkupLMModel',
	    'MarkupLMPreTrainedModel',
	]


if TYPE_CHECKING:
	from .configuration_markuplm import MARKUPLM_PRETRAINED_CONFIG_ARCHIVE_MAP, MarkupLMConfig
	from .feature_extraction_markuplm import MarkupLMFeatureExtractor
	from .processing_markuplm import MarkupLMProcessor
	from .tokenization_markuplm import MarkupLMTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_markuplm_fast import MarkupLMTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_markuplm import (
		    MARKUPLM_PRETRAINED_MODEL_ARCHIVE_LIST,
		    MarkupLMForQuestionAnswering,
		    MarkupLMForSequenceClassification,
		    MarkupLMForTokenClassification,
		    MarkupLMModel,
		    MarkupLMPreTrainedModel,
		)


else:
	import sys

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


