

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







	def __init__( self:			Optional[int]	,			__UpperCamelCase:			Dict	,			__UpperCamelCase:			Optional[int]=13	,			__UpperCamelCase:			Optional[Any]=3	,			__UpperCamelCase:			Union[str, Any]=18	,			__UpperCamelCase:			Tuple=30	,			__UpperCamelCase:			str=4_00	,			__UpperCamelCase:			Tuple=True	,			__UpperCamelCase:			str=None	,			__UpperCamelCase:			List[str]=True	,			__UpperCamelCase:			Any=[0.5, 0.5, 0.5]	,			__UpperCamelCase:			Optional[Any]=[0.5, 0.5, 0.5]	,			):

						'''simple docstring'''





						__magic_name__				=     size if size is not None else {'height': 18, 'width': 18}
						__magic_name__				=     parent
						__magic_name__				=     batch_size
						__magic_name__				=     num_channels
						__magic_name__				=     image_size
						__magic_name__				=     min_resolution
						__magic_name__				=     max_resolution
						__magic_name__				=     do_resize
						__magic_name__				=     size
						__magic_name__				=     do_normalize
						__magic_name__				=     image_mean
						__magic_name__				=     image_std







	def 						_SCREAMING_SNAKE_CASE				( self:			Tuple   ):

						'''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 					__UpperCamelCase					(       SCREAMING_SNAKE_CASE	,    unittest.TestCase      ):
	_lowercase	: Optional[int]												=	EfficientNetImageProcessor if is_vision_available() else None







	def 						_SCREAMING_SNAKE_CASE				( self:			Optional[Any]   ):

						'''simple docstring'''





						__magic_name__				=     EfficientNetImageProcessorTester(self   )







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

						'''simple docstring'''





						return self.image_processor_tester.prepare_image_processor_dict()







	def 						_SCREAMING_SNAKE_CASE				( self:			int   ):

						'''simple docstring'''





						__magic_name__				=     self.image_processing_class(**self.image_processor_dict   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'image_mean'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'image_std'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'do_normalize'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'do_resize'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'size'   )   )







	def 						_SCREAMING_SNAKE_CASE				( self:			List[Any]   ):

						'''simple docstring'''





						__magic_name__				=     self.image_processing_class.from_dict(self.image_processor_dict   )
						self.assertEqual(image_processor.size	,			{'height': 18, 'width': 18}   )

						__magic_name__				=     self.image_processing_class.from_dict(self.image_processor_dict	,			size=42   )
						self.assertEqual(image_processor.size	,			{'height': 42, 'width': 42}   )







	def 						_SCREAMING_SNAKE_CASE				( self:			Union[str, Any]   ):

						'''simple docstring'''





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

						# Test not batched input
						__magic_name__				=     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
						__magic_name__				=     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.size['height'],
						        self.image_processor_tester.size['width'],
						    )	,			)







	def 						_SCREAMING_SNAKE_CASE				( self:			Union[str, Any]   ):

						'''simple docstring'''





						__magic_name__				=     self.image_processing_class(**self.image_processor_dict   )
						# create random numpy tensors
						__magic_name__				=     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
						__magic_name__				=     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
						__magic_name__				=     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.size['height'],
						        self.image_processor_tester.size['width'],
						    )	,			)







	def 						_SCREAMING_SNAKE_CASE				( self:			List[Any]   ):

						'''simple docstring'''





						__magic_name__				=     self.image_processing_class(**self.image_processor_dict   )
						# create random PyTorch tensors
						__magic_name__				=     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
						__magic_name__				=     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
						__magic_name__				=     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.size['height'],
						        self.image_processor_tester.size['width'],
						    )	,			)







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A__							=				{"configuration_pegasus": ["PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP", "PegasusConfig"]}

try:
						if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				["PegasusTokenizer"]

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				["PegasusTokenizerFast"]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				[
						    "PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "PegasusForCausalLM",
						    "PegasusForConditionalGeneration",
						    "PegasusModel",
						    "PegasusPreTrainedModel",
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				[
						    "TFPegasusForConditionalGeneration",
						    "TFPegasusModel",
						    "TFPegasusPreTrainedModel",
						]

try:
						if not is_flax_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				[
						    "FlaxPegasusForConditionalGeneration",
						    "FlaxPegasusModel",
						    "FlaxPegasusPreTrainedModel",
						]


if TYPE_CHECKING:
						from .configuration_pegasus import PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP, PegasusConfig

						try:
												if not is_sentencepiece_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_pegasus import PegasusTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_pegasus_fast import PegasusTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_pegasus import (
												    PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
												    PegasusForCausalLM,
												    PegasusForConditionalGeneration,
												    PegasusModel,
												    PegasusPreTrainedModel,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_pegasus import TFPegasusForConditionalGeneration, TFPegasusModel, TFPegasusPreTrainedModel

						try:
												if not is_flax_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_flax_pegasus import (
												    FlaxPegasusForConditionalGeneration,
												    FlaxPegasusModel,
												    FlaxPegasusPreTrainedModel,
												)

else:
						import sys

						A__							=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




