




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





						def __init__(							self      :	Tuple     ,a__      :	Tuple     ,a__      :	List[str]=7     ,a__      :	Any=3     ,a__      :	List[Any]=30     ,a__      :	Tuple=400     ,a__      :	Any=True     ,a__      :	Dict=None     ,a__      :	Union[str, Any]=0.9     ,a__      :	List[str]=None     ,a__      :	List[str]=True     ,a__      :	int=[0.5, 0.5, 0.5]     ,a__      :	List[str]=[0.5, 0.5, 0.5]     ,)						->       str:




											"""simple docstring"""







											_lowerCAmelCase:List[Any]									=  size if size is not None else {'''shortest_edge''': 30}
											_lowerCAmelCase:Optional[Any]									=  crop_size if crop_size is not None else {'''height''': 30, '''width''': 30}
											_lowerCAmelCase:Optional[Any]									=  parent
											_lowerCAmelCase:Union[str, Any]									=  batch_size
											_lowerCAmelCase:Union[str, Any]									=  num_channels
											_lowerCAmelCase:Union[str, Any]									=  min_resolution
											_lowerCAmelCase:int									=  max_resolution
											_lowerCAmelCase:Optional[int]									=  do_resize_and_center_crop
											_lowerCAmelCase:Any									=  size
											_lowerCAmelCase:List[Any]									=  crop_pct
											_lowerCAmelCase:Any									=  crop_size
											_lowerCAmelCase:Dict									=  do_normalize
											_lowerCAmelCase:Union[str, Any]									=  image_mean
											_lowerCAmelCase:List[Any]									=  image_std







						def       __UpperCamelCase     (							self      :	List[Any])						->       Tuple:




											"""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   a__     (       UpperCamelCase_					,	unittest.TestCase  ):
						snake_case__             = PoolFormerImageProcessor if is_vision_available() else None





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




											"""simple docstring"""







											_lowerCAmelCase:Dict									=  PoolFormerImageProcessingTester(self)





						@property
						def       __UpperCamelCase     (							self      :	Optional[int])						->       Optional[Any]:




											"""simple docstring"""







											return self.image_processor_tester.prepare_image_processor_dict()





						def       __UpperCamelCase     (							self      :	Any)						->       Tuple:




											"""simple docstring"""







											_lowerCAmelCase:int									=  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       __UpperCamelCase     (							self      :	Any)						->       Tuple:




											"""simple docstring"""







											_lowerCAmelCase:str									=  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})

											_lowerCAmelCase:Dict									=  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      :	int)						->       Tuple:




											"""simple docstring"""







											pass





						def       __UpperCamelCase     (							self      :	str)						->       Any:




											"""simple docstring"""







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

											# Test not batched input
											_lowerCAmelCase: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.crop_size['''height'''],
											        self.image_processor_tester.crop_size['''width'''],
											    )     ,)

											# Test batched
											_lowerCAmelCase:Tuple									=  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       __UpperCamelCase     (							self      :	str)						->       Tuple:




											"""simple docstring"""







											_lowerCAmelCase:Any									=  self.image_processing_class(**self.image_processor_dict)
											# create random numpy tensors
											_lowerCAmelCase:Any									=  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
											_lowerCAmelCase:Dict									=  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
											_lowerCAmelCase:int									=  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       __UpperCamelCase     (							self      :	List[str])						->       Union[str, Any]:




											"""simple docstring"""







											_lowerCAmelCase:Union[str, Any]									=  self.image_processing_class(**self.image_processor_dict)
											# create random PyTorch tensors
											_lowerCAmelCase:Optional[int]									=  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
											_lowerCAmelCase:List[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.crop_size['''height'''],
											        self.image_processor_tester.crop_size['''width'''],
											    )     ,)

											# Test batched
											_lowerCAmelCase:List[str]									=  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_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCamelCase__						=			{
    '''configuration_convbert''': ['''CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ConvBertConfig''', '''ConvBertOnnxConfig'''],
    '''tokenization_convbert''': ['''ConvBertTokenizer'''],
}

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

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCamelCase__						=			[
				    '''CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
				    '''ConvBertForMaskedLM''',
				    '''ConvBertForMultipleChoice''',
				    '''ConvBertForQuestionAnswering''',
				    '''ConvBertForSequenceClassification''',
				    '''ConvBertForTokenClassification''',
				    '''ConvBertLayer''',
				    '''ConvBertModel''',
				    '''ConvBertPreTrainedModel''',
				    '''load_tf_weights_in_convbert''',
				]


try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCamelCase__						=			[
				    '''TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
				    '''TFConvBertForMaskedLM''',
				    '''TFConvBertForMultipleChoice''',
				    '''TFConvBertForQuestionAnswering''',
				    '''TFConvBertForSequenceClassification''',
				    '''TFConvBertForTokenClassification''',
				    '''TFConvBertLayer''',
				    '''TFConvBertModel''',
				    '''TFConvBertPreTrainedModel''',
				]


if TYPE_CHECKING:
				from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
				from .tokenization_convbert import ConvBertTokenizer

				try:
								if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_convbert_fast import ConvBertTokenizerFast

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_convbert import (
								    CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
								    ConvBertForMaskedLM,
								    ConvBertForMultipleChoice,
								    ConvBertForQuestionAnswering,
								    ConvBertForSequenceClassification,
								    ConvBertForTokenClassification,
								    ConvBertLayer,
								    ConvBertModel,
								    ConvBertPreTrainedModel,
								    load_tf_weights_in_convbert,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_convbert import (
								    TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TFConvBertForMaskedLM,
								    TFConvBertForMultipleChoice,
								    TFConvBertForQuestionAnswering,
								    TFConvBertForSequenceClassification,
								    TFConvBertForTokenClassification,
								    TFConvBertLayer,
								    TFConvBertModel,
								    TFConvBertPreTrainedModel,
								)


else:
				import sys

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






