


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





							'''simple docstring'''


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






							def UpperCAmelCase_			(					self						):
											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 					lowercase__						(		_snake_case  ,  unittest.TestCase      ):





							'''simple docstring'''


							A_							:   Optional[Any]   			=						EfficientNetImageProcessor if is_vision_available() else None






							def UpperCAmelCase_			(					self						):
											_SCREAMING_SNAKE_CASE				: Any  	=   EfficientNetImageProcessorTester(self						)






							@property
							def UpperCAmelCase_			(					self						):
											return self.image_processor_tester.prepare_image_processor_dict()






							def UpperCAmelCase_			(					self						):
											_SCREAMING_SNAKE_CASE				: str  	=   self.image_processing_class(**self.image_processor_dict						)
											self.assertTrue(hasattr(__snake_case					,      """image_mean"""						)						)
											self.assertTrue(hasattr(__snake_case					,      """image_std"""						)						)
											self.assertTrue(hasattr(__snake_case					,      """do_normalize"""						)						)
											self.assertTrue(hasattr(__snake_case					,      """do_resize"""						)						)
											self.assertTrue(hasattr(__snake_case					,      """size"""						)						)






							def UpperCAmelCase_			(					self						):
											_SCREAMING_SNAKE_CASE				: int  	=   self.image_processing_class.from_dict(self.image_processor_dict						)
											self.assertEqual(image_processor.size					,      {"""height""": 18, """width""": 18}						)

											_SCREAMING_SNAKE_CASE				: Union[str, Any]  	=   self.image_processing_class.from_dict(self.image_processor_dict					,      size=42						)
											self.assertEqual(image_processor.size					,      {"""height""": 42, """width""": 42}						)






							def UpperCAmelCase_			(					self						):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE				: Optional[int]  	=   self.image_processing_class(**self.image_processor_dict						)
											# create random PIL images
											_SCREAMING_SNAKE_CASE				: Dict  	=   prepare_image_inputs(self.image_processor_tester					,      equal_resolution=__snake_case						)
											for image in image_inputs:
															self.assertIsInstance(__snake_case					,      Image.Image						)

											# Test not batched input
											_SCREAMING_SNAKE_CASE				: Optional[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
											_SCREAMING_SNAKE_CASE				: Optional[Any]  	=   image_processing(__snake_case					,      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 UpperCAmelCase_			(					self						):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE				: List[str]  	=   self.image_processing_class(**self.image_processor_dict						)
											# create random numpy tensors
											_SCREAMING_SNAKE_CASE				: int  	=   prepare_image_inputs(self.image_processor_tester					,      equal_resolution=__snake_case					,      numpify=__snake_case						)
											for image in image_inputs:
															self.assertIsInstance(__snake_case					,      np.ndarray						)

											# Test not batched input
											_SCREAMING_SNAKE_CASE				: List[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
											_SCREAMING_SNAKE_CASE				: Any  	=   image_processing(__snake_case					,      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 UpperCAmelCase_			(					self						):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE				: Optional[Any]  	=   self.image_processing_class(**self.image_processor_dict						)
											# create random PyTorch tensors
											_SCREAMING_SNAKE_CASE				: Dict  	=   prepare_image_inputs(self.image_processor_tester					,      equal_resolution=__snake_case					,      torchify=__snake_case						)
											for image in image_inputs:
															self.assertIsInstance(__snake_case					,      torch.Tensor						)

											# Test not batched input
											_SCREAMING_SNAKE_CASE				: 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
											_SCREAMING_SNAKE_CASE				: Union[str, Any]  	=   image_processing(__snake_case					,      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 typing import TYPE_CHECKING

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


UpperCAmelCase_	:     Union[str, Any]							     =	{'configuration_pegasus': ['PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP', 'PegasusConfig']}

try:
				if not is_sentencepiece_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Dict							     =	['PegasusTokenizer']

try:
				if not is_tokenizers_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Optional[int]							     =	['PegasusTokenizerFast']

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Optional[int]							     =	[
				    'PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'PegasusForCausalLM',
				    'PegasusForConditionalGeneration',
				    'PegasusModel',
				    'PegasusPreTrainedModel',
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Optional[Any]							     =	[
				    'TFPegasusForConditionalGeneration',
				    'TFPegasusModel',
				    'TFPegasusPreTrainedModel',
				]

try:
				if not is_flax_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Any							     =	[
				    '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

				UpperCAmelCase_	:     List[str]							     =	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




