






'''simple docstring'''


import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
class  _SCREAMING_SNAKE_CASE				(		SCREAMING_SNAKE_CASE						):


			'''simple docstring'''





			__a				:				Optional[int]         =       ["image_processor", "tokenizer"]
			__a				:				Tuple         =       "AutoImageProcessor"
			__a				:				Tuple         =       "AutoTokenizer"






			def __init__( self				:    List[Any]			,   lowercase				:    List[Any]=None			,   lowercase				:    int=None			,   **lowercase				:    Tuple      )				->     Optional[Any]:

									'''simple docstring'''







									UpperCamelCase__       =			None
									if "feature_extractor" in kwargs:
															warnings.warn(
															    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
															    """ instead."""			,   lowercase			,   )
															UpperCamelCase__       =			kwargs.pop("""feature_extractor"""      )

									UpperCamelCase__       =			image_processor if image_processor is not None else feature_extractor
									if image_processor is None:
															raise ValueError("""You have to specify an image_processor."""      )
									if tokenizer is None:
															raise ValueError("""You have to specify a tokenizer."""      )

									super().__init__(lowercase			,   lowercase      )
									UpperCamelCase__       =			self.image_processor






			def __call__( self				:    Any			,   lowercase				:    Any=None			,   lowercase				:    Tuple=None			,   lowercase				:    Optional[Any]=None			,   **lowercase				:    Union[str, Any]      )				->     Optional[int]:

									'''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:
															UpperCamelCase__       =			self.tokenizer(lowercase			,   return_tensors=lowercase			,   **lowercase      )

									if images is not None:
															UpperCamelCase__       =			self.image_processor(lowercase			,   return_tensors=lowercase			,   **lowercase      )

									if text is not None and images is not None:
															UpperCamelCase__       =			image_features.pixel_values
															return encoding
									elif text is not None:
															return encoding
									else:
															return BatchEncoding(data=dict(**lowercase      )			,   tensor_type=lowercase      )






			def 					A   ( self				:    int			,   *lowercase				:    List[str]			,   **lowercase				:    Tuple      )				->     str:

									'''simple docstring'''







									return self.tokenizer.batch_decode(*lowercase			,   **lowercase      )






			def 					A   ( self				:    List[Any]			,   *lowercase				:    str			,   **lowercase				:    Tuple      )				->     Optional[int]:

									'''simple docstring'''







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






			@property
			def 					A   ( self				:    List[Any]      )				->     int:

									'''simple docstring'''







									UpperCamelCase__       =			self.tokenizer.model_input_names
									UpperCamelCase__       =			self.image_processor.model_input_names
									return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names      )      )






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

									'''simple docstring'''







									warnings.warn(
									    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""			,   lowercase			,   )
									return self.image_processor_class







			@property
			def 					A   ( self				:    Dict      )				->     Tuple:

									'''simple docstring'''







									warnings.warn(
									    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""			,   lowercase			,   )
									return self.image_processor








'''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 EfficientNetImageProcessor
class  _SCREAMING_SNAKE_CASE				(		unittest.TestCase						):


			'''simple docstring'''





			def __init__( self				:    List[str]			,   lowercase				:    Optional[Any]			,   lowercase				:    int=1_3			,   lowercase				:    List[Any]=3			,   lowercase				:    int=1_8			,   lowercase				:    List[Any]=3_0			,   lowercase				:    Optional[int]=4_0_0			,   lowercase				:    Any=True			,   lowercase				:    int=None			,   lowercase				:    Any=True			,   lowercase				:    Optional[int]=[0.5, 0.5, 0.5]			,   lowercase				:    List[Any]=[0.5, 0.5, 0.5]			,   )				->     List[Any]:

									'''simple docstring'''







									UpperCamelCase__       =			size if size is not None else {"""height""": 1_8, """width""": 1_8}
									UpperCamelCase__       =			parent
									UpperCamelCase__       =			batch_size
									UpperCamelCase__       =			num_channels
									UpperCamelCase__       =			image_size
									UpperCamelCase__       =			min_resolution
									UpperCamelCase__       =			max_resolution
									UpperCamelCase__       =			do_resize
									UpperCamelCase__       =			size
									UpperCamelCase__       =			do_normalize
									UpperCamelCase__       =			image_mean
									UpperCamelCase__       =			image_std







			def 					A   ( self				:    Optional[Any]      )				->     Any:

									'''simple docstring'''







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


			'''simple docstring'''





			__a				:				List[Any]         =       EfficientNetImageProcessor if is_vision_available() else None






			def 					A   ( self				:    Optional[Any]      )				->     str:

									'''simple docstring'''







									UpperCamelCase__       =			EfficientNetImageProcessorTester(self      )






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

									'''simple docstring'''







									return self.image_processor_tester.prepare_image_processor_dict()






			def 					A   ( self				:    Dict      )				->     str:

									'''simple docstring'''







									UpperCamelCase__       =			self.image_processing_class(**self.image_processor_dict      )
									self.assertTrue(hasattr(lowercase			,   """image_mean"""      )      )
									self.assertTrue(hasattr(lowercase			,   """image_std"""      )      )
									self.assertTrue(hasattr(lowercase			,   """do_normalize"""      )      )
									self.assertTrue(hasattr(lowercase			,   """do_resize"""      )      )
									self.assertTrue(hasattr(lowercase			,   """size"""      )      )






			def 					A   ( self				:    List[str]      )				->     Optional[int]:

									'''simple docstring'''







									UpperCamelCase__       =			self.image_processing_class.from_dict(self.image_processor_dict      )
									self.assertEqual(image_processor.size			,   {"""height""": 1_8, """width""": 1_8}      )

									UpperCamelCase__       =			self.image_processing_class.from_dict(self.image_processor_dict			,   size=4_2      )
									self.assertEqual(image_processor.size			,   {"""height""": 4_2, """width""": 4_2}      )






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

									'''simple docstring'''







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

									# Test not batched input
									UpperCamelCase__       =			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
									UpperCamelCase__       =			image_processing(lowercase			,   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 					A   ( self				:    Dict      )				->     Optional[int]:

									'''simple docstring'''







									UpperCamelCase__       =			self.image_processing_class(**self.image_processor_dict      )
									# create random numpy tensors
									UpperCamelCase__       =			prepare_image_inputs(self.image_processor_tester			,   equal_resolution=lowercase			,   numpify=lowercase      )
									for image in image_inputs:
															self.assertIsInstance(lowercase			,   np.ndarray      )

									# Test not batched input
									UpperCamelCase__       =			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
									UpperCamelCase__       =			image_processing(lowercase			,   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 					A   ( self				:    Optional[int]      )				->     List[str]:

									'''simple docstring'''







									UpperCamelCase__       =			self.image_processing_class(**self.image_processor_dict      )
									# create random PyTorch tensors
									UpperCamelCase__       =			prepare_image_inputs(self.image_processor_tester			,   equal_resolution=lowercase			,   torchify=lowercase      )
									for image in image_inputs:
															self.assertIsInstance(lowercase			,   torch.Tensor      )

									# Test not batched input
									UpperCamelCase__       =			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
									UpperCamelCase__       =			image_processing(lowercase			,   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"""],
									    )			,   )
