



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 EfficientNetImageProcessor




class 				lowerCAmelCase__	(						unittest.TestCase    ):







					def __init__(							self   :  Tuple      ,		_A   :  Dict      ,		_A   :  Optional[Any]=13      ,		_A   :  Any=3      ,		_A   :  Tuple=18      ,		_A   :  str=30      ,		_A   :  Union[str, Any]=400      ,		_A   :  Union[str, Any]=True      ,		_A   :  Dict=None      ,		_A   :  Union[str, Any]=True      ,		_A   :  Any=[0.5, 0.5, 0.5]      ,		_A   :  Optional[Any]=[0.5, 0.5, 0.5]      ,		):
											A__						:				Union[str, Any]         =			size if size is not None else {"""height""": 18, """width""": 18}
											A__						:				List[Any]         =			parent
											A__						:				Tuple         =			batch_size
											A__						:				List[Any]         =			num_channels
											A__						:				int         =			image_size
											A__						:				Optional[int]         =			min_resolution
											A__						:				Union[str, Any]         =			max_resolution
											A__						:				str         =			do_resize
											A__						:				List[str]         =			size
											A__						:				Optional[Any]         =			do_normalize
											A__						:				Dict         =			image_mean
											A__						:				Optional[Any]         =			image_std







					def 			_lowercase      (							self   :  Tuple):
											return {
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											    "do_normalize": self.do_normalize,
											    "do_resize": self.do_resize,
											    "size": self.size,
											}




@require_torch
@require_vision
class 				lowerCAmelCase__	(						_SCREAMING_SNAKE_CASE       ,				unittest.TestCase    ):
					__A  :     Any     =    EfficientNetImageProcessor if is_vision_available() else None







					def 			_lowercase      (							self   :  str):
											A__						:				Optional[Any]         =			EfficientNetImageProcessorTester(self)







					@property
					def 			_lowercase      (							self   :  List[Any]):
											return self.image_processor_tester.prepare_image_processor_dict()







					def 			_lowercase      (							self   :  str):
											A__						:				Optional[Any]         =			self.image_processing_class(**self.image_processor_dict)
											self.assertTrue(hasattr(_A      ,		"image_mean"))
											self.assertTrue(hasattr(_A      ,		"image_std"))
											self.assertTrue(hasattr(_A      ,		"do_normalize"))
											self.assertTrue(hasattr(_A      ,		"do_resize"))
											self.assertTrue(hasattr(_A      ,		"size"))







					def 			_lowercase      (							self   :  str):
											A__						:				Any         =			self.image_processing_class.from_dict(self.image_processor_dict)
											self.assertEqual(image_processor.size      ,		{"height": 18, "width": 18})

											A__						:				Tuple         =			self.image_processing_class.from_dict(self.image_processor_dict      ,		size=42)
											self.assertEqual(image_processor.size      ,		{"height": 42, "width": 42})







					def 			_lowercase      (							self   :  Tuple):
											A__						:				Tuple         =			self.image_processing_class(**self.image_processor_dict)
											# create random PIL images
											A__						:				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
											A__						:				int         =			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
											A__						:				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.size["height"],
											        self.image_processor_tester.size["width"],
											    )      ,		)







					def 			_lowercase      (							self   :  List[str]):
											A__						:				Optional[int]         =			self.image_processing_class(**self.image_processor_dict)
											# create random numpy tensors
											A__						:				int         =			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__						:				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
											A__						:				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.size["height"],
											        self.image_processor_tester.size["width"],
											    )      ,		)







					def 			_lowercase      (							self   :  str):
											A__						:				List[str]         =			self.image_processing_class(**self.image_processor_dict)
											# create random PyTorch tensors
											A__						:				List[Any]         =			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__						:				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.size["height"],
											        self.image_processor_tester.size["width"],
											    )      ,		)

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

'''simple docstring'''
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding







class 			__A					(			_SCREAMING_SNAKE_CASE      ):
 lowerCamelCase												=['''image_processor''', '''tokenizer''']
 lowerCamelCase												='''EfficientNetImageProcessor'''
 lowerCamelCase												=('''BertTokenizer''', '''BertTokenizerFast''')
 def __init__( self      :     str					, lowerCamelCase      :     Optional[int]					, lowerCamelCase      :     Tuple							):



   """simple docstring"""





   super().__init__(lowerCamelCase					, lowerCamelCase							)
 def __call__( self      :     Tuple					, lowerCamelCase      :     str=None					, lowerCamelCase      :     Tuple=None					, lowerCamelCase      :     int="max_length"					, lowerCamelCase      :     int=64					, lowerCamelCase      :     Union[str, Any]=None					, **lowerCamelCase      :     Dict							):



   """simple docstring"""





   if text is None and images is None:
     raise ValueError("""You have to specify either text or images. Both cannot be none."""							)

   if text is not None:
     __A		:  str       				=		self.tokenizer(
         lowerCamelCase					, padding=lowerCamelCase					, max_length=lowerCamelCase					, return_tensors=lowerCamelCase					, **lowerCamelCase							)

   if images is not None:
     __A		:  Optional[Any]       				=		self.image_processor(lowerCamelCase					, return_tensors=lowerCamelCase					, **lowerCamelCase							)

   if text is not None and images is not None:
     __A		:  Optional[int]       				=		image_features.pixel_values
     return encoding
   elif text is not None:
     return encoding
   else:
     return BatchEncoding(data=dict(**lowerCamelCase							)					, tensor_type=lowerCamelCase							)
 def 		lowercase_( self      :     Any					, *lowerCamelCase      :     Optional[Any]					, **lowerCamelCase      :     Union[str, Any]							):



   """simple docstring"""





   return self.tokenizer.batch_decode(*lowerCamelCase					, **lowerCamelCase							)
 def 		lowercase_( self      :     Any					, *lowerCamelCase      :     List[Any]					, **lowerCamelCase      :     Union[str, Any]							):



   """simple docstring"""





   return self.tokenizer.decode(*lowerCamelCase					, **lowerCamelCase							)






 @property
 def 		lowercase_( self      :     int							):



   """simple docstring"""





   __A		:  Dict       				=		self.tokenizer.model_input_names
   __A		:  int       				=		self.image_processor.model_input_names
   return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names							)							)



