
'''simple docstring'''



import inspect
import unittest

from transformers import EfficientNetConfig
from transformers.testing_utils import is_pipeline_test, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import EfficientNetForImageClassification, EfficientNetModel
					from transformers.models.efficientnet.modeling_efficientnet import EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import AutoImageProcessor

class 				_a			:





							"""simple docstring"""




							def __init__(							self    ,							A__    ,							A__=13    ,							A__=32    ,							A__=3    ,							A__=[3, 3, 5]    ,							A__=[32, 16, 24]    ,							A__=[16, 24, 40]    ,							A__=[1, 1, 2]    ,							A__=[1, 1, 2]    ,							A__=[1, 6, 6]    ,							A__=True    ,							A__=True    ,							A__=37    ,							A__="gelu"    ,							A__=10    ,							)      ->     List[Any]:
										_SCREAMING_SNAKE_CASE       	=			parent
										_SCREAMING_SNAKE_CASE       	=			batch_size
										_SCREAMING_SNAKE_CASE       	=			image_size
										_SCREAMING_SNAKE_CASE       	=			num_channels
										_SCREAMING_SNAKE_CASE       	=			kernel_sizes
										_SCREAMING_SNAKE_CASE       	=			in_channels
										_SCREAMING_SNAKE_CASE       	=			out_channels
										_SCREAMING_SNAKE_CASE       	=			strides
										_SCREAMING_SNAKE_CASE       	=			num_block_repeats
										_SCREAMING_SNAKE_CASE       	=			expand_ratios
										_SCREAMING_SNAKE_CASE       	=			is_training
										_SCREAMING_SNAKE_CASE       	=			hidden_act
										_SCREAMING_SNAKE_CASE       	=			num_labels
										_SCREAMING_SNAKE_CASE       	=			use_labels






							def     UpperCamelCase			(							self )      ->     Optional[int]:
										_SCREAMING_SNAKE_CASE       	=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

										_SCREAMING_SNAKE_CASE       	=			None
										if self.use_labels:
													_SCREAMING_SNAKE_CASE       	=			ids_tensor([self.batch_size]    ,							self.num_labels )

										_SCREAMING_SNAKE_CASE       	=			self.get_config()
										return config, pixel_values, labels






							def     UpperCamelCase			(							self )      ->     str:
										return EfficientNetConfig(
										    num_channels=self.num_channels    ,							kernel_sizes=self.kernel_sizes    ,							in_channels=self.in_channels    ,							out_channels=self.out_channels    ,							strides=self.strides    ,							num_block_repeats=self.num_block_repeats    ,							expand_ratios=self.expand_ratios    ,							hidden_act=self.hidden_act    ,							num_labels=self.num_labels    ,							)






							def     UpperCamelCase			(							self    ,							A__    ,							A__    ,							A__ )      ->     Tuple:
										_SCREAMING_SNAKE_CASE       	=			EfficientNetModel(config=A__ )
										model.to(A__ )
										model.eval()
										_SCREAMING_SNAKE_CASE       	=			model(A__ )
										# expected last hidden states: B, C, H // 4, W // 4
										self.parent.assertEqual(
										    result.last_hidden_state.shape    ,							(self.batch_size, config.hidden_dim, self.image_size // 4, self.image_size // 4)    ,							)






							def     UpperCamelCase			(							self    ,							A__    ,							A__    ,							A__ )      ->     Union[str, Any]:
										_SCREAMING_SNAKE_CASE       	=			EfficientNetForImageClassification(A__ )
										model.to(A__ )
										model.eval()
										_SCREAMING_SNAKE_CASE       	=			model(A__    ,							labels=A__ )
										self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.num_labels) )






							def     UpperCamelCase			(							self )      ->     Optional[Any]:
										_SCREAMING_SNAKE_CASE       	=			self.prepare_config_and_inputs()
										_SCREAMING_SNAKE_CASE       	=			config_and_inputs
										_SCREAMING_SNAKE_CASE       	=			{"pixel_values": pixel_values}
										return config, inputs_dict






@require_torch
class 				_a			(snake_case_					,   snake_case_					,   unittest.TestCase):





							"""simple docstring"""




							SCREAMING_SNAKE_CASE =					(EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
							SCREAMING_SNAKE_CASE =					(
							    {"""feature-extraction""": EfficientNetModel, """image-classification""": EfficientNetForImageClassification}
							    if is_torch_available()
							    else {}
							)

							SCREAMING_SNAKE_CASE =					False
							SCREAMING_SNAKE_CASE =					False
							SCREAMING_SNAKE_CASE =					False
							SCREAMING_SNAKE_CASE =					False
							SCREAMING_SNAKE_CASE =					False






							def     UpperCamelCase			(							self )      ->     Optional[Any]:
										_SCREAMING_SNAKE_CASE       	=			EfficientNetModelTester(self )
										_SCREAMING_SNAKE_CASE       	=			ConfigTester(
										    self    ,							config_class=A__    ,							has_text_modality=A__    ,							hidden_size=37 )






							def     UpperCamelCase			(							self )      ->     int:
										self.create_and_test_config_common_properties()
										self.config_tester.create_and_test_config_to_json_string()
										self.config_tester.create_and_test_config_to_json_file()
										self.config_tester.create_and_test_config_from_and_save_pretrained()
										self.config_tester.create_and_test_config_with_num_labels()
										self.config_tester.check_config_can_be_init_without_params()
										self.config_tester.check_config_arguments_init()






							def     UpperCamelCase			(							self )      ->     int:
										return






							@unittest.skip(reason="""EfficientNet does not use inputs_embeds""" )
							def     UpperCamelCase			(							self )      ->     Union[str, Any]:
										pass






							@unittest.skip(reason="""EfficientNet does not support input and output embeddings""" )
							def     UpperCamelCase			(							self )      ->     Union[str, Any]:
										pass






							@unittest.skip(reason="""EfficientNet does not use feedforward chunking""" )
							def     UpperCamelCase			(							self )      ->     Optional[int]:
										pass






							def     UpperCamelCase			(							self )      ->     Union[str, Any]:
										_SCREAMING_SNAKE_CASE       	=			self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
													_SCREAMING_SNAKE_CASE       	=			model_class(A__ )
													_SCREAMING_SNAKE_CASE       	=			inspect.signature(model.forward )
													# signature.parameters is an OrderedDict => so arg_names order is deterministic
													_SCREAMING_SNAKE_CASE       	=			[*signature.parameters.keys()]

													_SCREAMING_SNAKE_CASE       	=			["pixel_values"]
													self.assertListEqual(arg_names[:1]    ,							A__ )






							def     UpperCamelCase			(							self )      ->     str:
										_SCREAMING_SNAKE_CASE       	=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*A__ )






							def     UpperCamelCase			(							self )      ->     Tuple:


										def check_hidden_states_output(A__    ,							A__    ,							A__ ):
													_SCREAMING_SNAKE_CASE       	=			model_class(A__ )
													model.to(A__ )
													model.eval()

													with torch.no_grad():
																_SCREAMING_SNAKE_CASE       	=			model(**self._prepare_for_class(A__    ,							A__ ) )

													_SCREAMING_SNAKE_CASE       	=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
													_SCREAMING_SNAKE_CASE       	=			sum(config.num_block_repeats ) * 4
													self.assertEqual(len(A__ )    ,							A__ )

													# EfficientNet's feature maps are of shape (batch_size, num_channels, height, width)
													self.assertListEqual(
													    list(hidden_states[0].shape[-2:] )    ,							[self.model_tester.image_size // 2, self.model_tester.image_size // 2]    ,							)

										_SCREAMING_SNAKE_CASE       	=			self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
													_SCREAMING_SNAKE_CASE       	=			True
													check_hidden_states_output(A__    ,							A__    ,							A__ )

													# check that output_hidden_states also work using config
													del inputs_dict["output_hidden_states"]
													_SCREAMING_SNAKE_CASE       	=			True

													check_hidden_states_output(A__    ,							A__    ,							A__ )






							def     UpperCamelCase			(							self )      ->     Tuple:
										_SCREAMING_SNAKE_CASE       	=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*A__ )






							@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests.""" )
							def     UpperCamelCase			(							self )      ->     str:
										pass






							@slow
							def     UpperCamelCase			(							self )      ->     Any:


										for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													_SCREAMING_SNAKE_CASE       	=			EfficientNetModel.from_pretrained(A__ )
													self.assertIsNotNone(A__ )






							@is_pipeline_test
							@require_vision
							@slow
							def     UpperCamelCase			(							self )      ->     Optional[Any]:
										super().test_pipeline_image_classification()






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




			"""simple docstring"""
			_SCREAMING_SNAKE_CASE       	=			Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
			return image







@require_torch
@require_vision
class 				_a			(unittest.TestCase):





							"""simple docstring"""




							@cached_property
							def     UpperCamelCase			(							self )      ->     str:
										return AutoImageProcessor.from_pretrained("""google/efficientnet-b7""" ) if is_vision_available() else None






							@slow
							def     UpperCamelCase			(							self )      ->     int:
										_SCREAMING_SNAKE_CASE       	=			EfficientNetForImageClassification.from_pretrained("""google/efficientnet-b7""" ).to(A__ )

										_SCREAMING_SNAKE_CASE       	=			self.default_image_processor
										_SCREAMING_SNAKE_CASE       	=			prepare_img()
										_SCREAMING_SNAKE_CASE       	=			image_processor(images=A__    ,							return_tensors="""pt""" ).to(A__ )

										# forward pass
										with torch.no_grad():
													_SCREAMING_SNAKE_CASE       	=			model(**A__ )

										# verify the logits
										_SCREAMING_SNAKE_CASE       	=			torch.Size((1, 10_00) )
										self.assertEqual(outputs.logits.shape    ,							A__ )

										_SCREAMING_SNAKE_CASE       	=			torch.tensor([0.0001, 0.0002, 0.0002] ).to(A__ )
										self.assertTrue(torch.allclose(outputs.logits[0, :3]    ,							A__    ,							atol=1E-4 ) )








'''simple docstring'''



def 				lowerCAmelCase_		(			SCREAMING_SNAKE_CASE_  )       ->       str:




   """simple docstring"""
   return " ".join(sorted(set(sentence.split()  )  )  )


if __name__ == "__main__":
     import doctest

     doctest.testmod()






