




'''simple docstring'''


import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VivitConfig
from transformers.models.auto import get_values
from transformers.testing_utils import 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


if is_torch_available():
 import torch
 from torch import nn

 from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VivitForVideoClassification, VivitModel
 from transformers.models.vivit.modeling_vivit import VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from transformers import VivitImageProcessor







class     SCREAMING_SNAKE_CASE						:






      def __init__(   self      :     Any	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Optional[Any]=2	,	lowercase__      :     Any=True	,	lowercase__      :     Dict=True	,	lowercase__      :     Optional[Any]=10	,	lowercase__      :     str=10	,	lowercase__      :     str=8	,	lowercase__      :     Dict=[2, 4, 4]	,	lowercase__      :     List[Any]=3	,	lowercase__      :     Optional[int]=768	,	lowercase__      :     List[Any]=5	,	lowercase__      :     Optional[int]=4	,	lowercase__      :     List[str]=37	,	lowercase__      :     Tuple="gelu_fast"	,	lowercase__      :     Optional[int]=0.0	,	lowercase__      :     str=0.0	,	lowercase__      :     Optional[int]=0.02	,	lowercase__      :     Dict=1e-0_6	,	lowercase__      :     List[str]=True	,	lowercase__      :     Tuple=None	,	):


           '''simple docstring'''

           a_    :       int    	=     parent
           a_    :       List[Any]    	=     batch_size
           a_    :       Tuple    	=     is_training
           a_    :       Dict    	=     use_labels
           a_    :       Dict    	=     num_labels
           a_    :       Dict    	=     image_size
           a_    :       Union[str, Any]    	=     num_frames
           a_    :       Tuple    	=     tubelet_size
           a_    :       str    	=     num_channels
           a_    :       Optional[Any]    	=     hidden_size
           a_    :       Tuple    	=     num_hidden_layers
           a_    :       List[str]    	=     num_attention_heads
           a_    :       Tuple    	=     intermediate_size
           a_    :       Optional[Any]    	=     hidden_act
           a_    :       Union[str, Any]    	=     hidden_dropout_prob
           a_    :       Union[str, Any]    	=     attention_probs_dropout_prob
           a_    :       Optional[Any]    	=     initializer_range
           a_    :       Optional[int]    	=     layer_norm_eps
           a_    :       List[Any]    	=     qkv_bias
           a_    :       List[Any]    	=     scope

           a_    :       Optional[Any]    	=     (
               (self.image_size // self.tubelet_size[2])
               * (self.image_size // self.tubelet_size[1])
               * (self.num_frames // self.tubelet_size[0])
           ) + 1  # CLS token






      def        lowercase_	(   self      :     List[str]					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     floats_tensor(
               [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]					)

           a_    :       Tuple    	=     None
           if self.use_labels:
                a_    :       Any    	=     ids_tensor([self.batch_size]	,	self.num_labels					)

           a_    :       Tuple    	=     self.get_config()

           return config, pixel_values, labels






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_    :       Union[str, Any]    	=     VivitConfig(
               num_frames=self.num_frames	,	image_size=self.image_size	,	tubelet_size=self.tubelet_size	,	num_channels=self.num_channels	,	hidden_size=self.hidden_size	,	num_hidden_layers=self.num_hidden_layers	,	num_attention_heads=self.num_attention_heads	,	intermediate_size=self.intermediate_size	,	hidden_act=self.hidden_act	,	hidden_dropout_prob=self.hidden_dropout_prob	,	attention_probs_dropout_prob=self.attention_probs_dropout_prob	,	initializer_range=self.initializer_range	,	layer_norm_eps=self.layer_norm_eps	,	qkv_bias=self.qkv_bias	,	)
           a_    :       Any    	=     self.num_labels
           return config






      def        lowercase_	(   self      :     Union[str, Any]	,	lowercase__      :     Dict	,	lowercase__      :     List[str]	,	lowercase__      :     str					):


           '''simple docstring'''

           a_    :       Union[str, Any]    	=     VivitModel(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Optional[Any]    	=     model(lowercase__					)
           self.parent.assertEqual(result.last_hidden_state.shape	,	(self.batch_size, self.seq_length, self.hidden_size)					)






      def        lowercase_	(   self      :     int	,	lowercase__      :     List[str]	,	lowercase__      :     Any	,	lowercase__      :     Tuple					):


           '''simple docstring'''

           a_    :       int    	=     VivitForVideoClassification(lowercase__					)
           model.to(lowercase__					)
           model.eval()

           a_    :       Dict    	=     model(lowercase__					)

           # verify the logits shape
           a_    :       Optional[Any]    	=     torch.Size((self.batch_size, self.num_labels)					)
           self.parent.assertEqual(result.logits.shape	,	lowercase__					)






      def        lowercase_	(   self      :     Optional[Any]					):


           '''simple docstring'''

           a_    :       Tuple    	=     self.prepare_config_and_inputs()
           a_	,    a_	,    a_    :       List[Any]    	=     config_and_inputs
           a_    :       int    	=     {"""pixel_values""": pixel_values}
           return config, inputs_dict







@require_torch
class     SCREAMING_SNAKE_CASE						(	snake_case_       ,			unittest.TestCase							):
      __magic_name__     :					Any             =				(VivitModel, VivitForVideoClassification) if is_torch_available() else ()

      __magic_name__     :					Dict             =				False
      __magic_name__     :					List[Any]             =				False
      __magic_name__     :					Tuple             =				False
      __magic_name__     :					Any             =				False






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_    :       Any    	=     VivitModelTester(self					)
           a_    :       Any    	=     ConfigTester(self	,	config_class=lowercase__	,	has_text_modality=lowercase__	,	hidden_size=37					)






      def        lowercase_	(   self      :     str	,	lowercase__      :     str	,	lowercase__      :     int	,	lowercase__      :     Dict=False					):


           '''simple docstring'''

           a_    :       int    	=     copy.deepcopy(lowercase__					)

           if return_labels:
                if model_class in get_values(lowercase__					):
                     a_    :       List[Any]    	=     torch.zeros(
                         self.model_tester.batch_size	,	dtype=torch.long	,	device=lowercase__					)

           return inputs_dict






      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           self.config_tester.run_common_tests()






      @unittest.skip(reason="""Vivit does not use inputs_embeds"""					)
      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           pass






      def        lowercase_	(   self      :     Optional[int]					):


           '''simple docstring'''

           a_	,    a_    :       Tuple    	=     self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                a_    :       Tuple    	=     model_class(lowercase__					)
                self.assertIsInstance(model.get_input_embeddings()	,	(nn.Module)					)
                a_    :       Union[str, Any]    	=     model.get_output_embeddings()
                self.assertTrue(x is None or isinstance(lowercase__	,	nn.Linear					)					)






      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

           a_	,    a_    :       Optional[int]    	=     self.model_tester.prepare_config_and_inputs_for_common()

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

                a_    :       Dict    	=     ["""pixel_values""", """head_mask"""]
                self.assertListEqual(arg_names[:2]	,	lowercase__					)






      def        lowercase_	(   self      :     str					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*lowercase__					)






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_    :       List[str]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_video_classification(*lowercase__					)






      @slow
      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           for model_name in VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                a_    :       List[str]    	=     VivitModel.from_pretrained(lowercase__					)
                self.assertIsNotNone(lowercase__					)






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_	,    a_    :       Any    	=     self.model_tester.prepare_config_and_inputs_for_common()
           a_    :       int    	=     True

           for model_class in self.all_model_classes:
                a_    :       Optional[Any]    	=     self.model_tester.seq_length

                a_    :       Dict    	=     True
                a_    :       Optional[int]    	=     False
                a_    :       List[Any]    	=     True
                a_    :       Optional[int]    	=     model_class(lowercase__					)
                model.to(lowercase__					)
                model.eval()
                with torch.no_grad():
                     a_    :       Any    	=     model(**self._prepare_for_class(lowercase__	,	lowercase__					)					)
                a_    :       int    	=     outputs.attentions
                self.assertEqual(len(lowercase__					)	,	self.model_tester.num_hidden_layers					)

                # check that output_attentions also work using config
                del inputs_dict["output_attentions"]
                a_    :       int    	=     True
                a_    :       Any    	=     model_class(lowercase__					)
                model.to(lowercase__					)
                model.eval()
                with torch.no_grad():
                     a_    :       Dict    	=     model(**self._prepare_for_class(lowercase__	,	lowercase__					)					)
                a_    :       Optional[Any]    	=     outputs.attentions
                self.assertEqual(len(lowercase__					)	,	self.model_tester.num_hidden_layers					)

                self.assertListEqual(
                    list(attentions[0].shape[-3:]					)	,	[self.model_tester.num_attention_heads, seq_len, seq_len]	,	)
                a_    :       Optional[Any]    	=     len(lowercase__					)

                # Check attention is always last and order is fine
                a_    :       int    	=     True
                a_    :       int    	=     True
                a_    :       Optional[Any]    	=     model_class(lowercase__					)
                model.to(lowercase__					)
                model.eval()
                with torch.no_grad():
                     a_    :       Tuple    	=     model(**self._prepare_for_class(lowercase__	,	lowercase__					)					)

                self.assertEqual(out_len + 1	,	len(lowercase__					)					)

                a_    :       List[Any]    	=     outputs.attentions

                self.assertEqual(len(lowercase__					)	,	self.model_tester.num_hidden_layers					)

                self.assertListEqual(
                    list(self_attentions[0].shape[-3:]					)	,	[self.model_tester.num_attention_heads, seq_len, seq_len]	,	)






      def        lowercase_	(   self      :     int					):


           '''simple docstring'''

           def check_hidden_states_output(lowercase__      :     Optional[int]	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     List[Any]					):
                a_    :       str    	=     model_class(lowercase__					)
                model.to(lowercase__					)
                model.eval()

                with torch.no_grad():
                     a_    :       Union[str, Any]    	=     model(**self._prepare_for_class(lowercase__	,	lowercase__					)					)

                a_    :       List[Any]    	=     outputs.hidden_states
                a_    :       Any    	=     self.model_tester.num_hidden_layers + 1
                self.assertEqual(len(lowercase__					)	,	lowercase__					)

                a_    :       str    	=     self.model_tester.seq_length

                self.assertListEqual(
                    list(hidden_states[0].shape[-2:]					)	,	[seq_length, self.model_tester.hidden_size]	,	)

           a_	,    a_    :       List[str]    	=     self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                a_    :       List[str]    	=     True
                check_hidden_states_output(lowercase__	,	lowercase__	,	lowercase__					)

                # check that output_hidden_states also work using config
                del inputs_dict["output_hidden_states"]
                a_    :       Union[str, Any]    	=     True

                check_hidden_states_output(lowercase__	,	lowercase__	,	lowercase__					)






      @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""					)
      def        lowercase_	(   self      :     int					):


           '''simple docstring'''

           pass



def    _SCREAMING_SNAKE_CASE    (			):




     """simple docstring"""


     a_    :       List[Any]    	=     hf_hub_download(
         repo_id="""hf-internal-testing/spaghetti-video"""   ,						filename="""eating_spaghetti_32_frames.npy"""   ,						repo_type="""dataset"""							)
     a_    :       int    	=     np.load(UpperCamelCase__							)
     return list(UpperCamelCase__							)







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






      @cached_property
      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

           return VivitImageProcessor() if is_vision_available() else None






      @slow
      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           a_    :       Any    	=     VivitForVideoClassification.from_pretrained("""google/vivit-b-16x2-kinetics400"""					).to(lowercase__					)

           a_    :       Tuple    	=     self.default_image_processor
           a_    :       Union[str, Any]    	=     prepare_video()
           a_    :       Any    	=     image_processor(lowercase__	,	return_tensors="""pt"""					).to(lowercase__					)

           # forward pass
           with torch.no_grad():
                a_    :       str    	=     model(**lowercase__					)

           # verify the logits
           a_    :       Dict    	=     torch.Size((1, 400)					)
           self.assertEqual(outputs.logits.shape	,	lowercase__					)

           # taken from original model
           a_    :       Optional[Any]    	=     torch.tensor([-1.0543, 2.0764, -0.2104, 0.4439, -0.9658]					).to(lowercase__					)

           self.assertTrue(torch.allclose(outputs.logits[0, :5]	,	lowercase__	,	atol=1e-4					)					)






'''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     SCREAMING_SNAKE_CASE						:






      def __init__(   self      :     Dict	,	lowercase__      :     Any	,	lowercase__      :     Tuple=13	,	lowercase__      :     Any=32	,	lowercase__      :     List[str]=3	,	lowercase__      :     Any=[3, 3, 5]	,	lowercase__      :     int=[32, 16, 24]	,	lowercase__      :     str=[16, 24, 40]	,	lowercase__      :     Optional[Any]=[1, 1, 2]	,	lowercase__      :     int=[1, 1, 2]	,	lowercase__      :     Tuple=[1, 6, 6]	,	lowercase__      :     Optional[Any]=True	,	lowercase__      :     Union[str, Any]=True	,	lowercase__      :     List[str]=37	,	lowercase__      :     Optional[int]="gelu"	,	lowercase__      :     str=10	,	):


           '''simple docstring'''

           a_    :       Dict    	=     parent
           a_    :       Any    	=     batch_size
           a_    :       str    	=     image_size
           a_    :       Tuple    	=     num_channels
           a_    :       Dict    	=     kernel_sizes
           a_    :       List[Any]    	=     in_channels
           a_    :       int    	=     out_channels
           a_    :       Union[str, Any]    	=     strides
           a_    :       List[Any]    	=     num_block_repeats
           a_    :       List[Any]    	=     expand_ratios
           a_    :       Dict    	=     is_training
           a_    :       Optional[int]    	=     hidden_act
           a_    :       List[Any]    	=     num_labels
           a_    :       List[str]    	=     use_labels






      def        lowercase_	(   self      :     Optional[int]					):


           '''simple docstring'''

           a_    :       List[Any]    	=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

           a_    :       List[Any]    	=     self.get_config()
           return config, pixel_values, labels






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           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        lowercase_	(   self      :     int	,	lowercase__      :     Any	,	lowercase__      :     Any	,	lowercase__      :     Optional[int]					):


           '''simple docstring'''

           a_    :       Tuple    	=     EfficientNetModel(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Optional[int]    	=     model(lowercase__					)
           # 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        lowercase_	(   self      :     Optional[Any]	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Any	,	lowercase__      :     str					):


           '''simple docstring'''

           a_    :       Dict    	=     EfficientNetForImageClassification(lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       str    	=     model(lowercase__	,	labels=lowercase__					)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.num_labels)					)






      def        lowercase_	(   self      :     int					):


           '''simple docstring'''

           a_    :       Union[str, Any]    	=     self.prepare_config_and_inputs()
           a_	,    a_	,    a_    :       Optional[Any]    	=     config_and_inputs
           a_    :       str    	=     {"""pixel_values""": pixel_values}
           return config, inputs_dict







@require_torch
class     SCREAMING_SNAKE_CASE						(	snake_case_       ,			snake_case_       ,			unittest.TestCase							):
      __magic_name__     :					Any             =				(EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
      __magic_name__     :					List[Any]             =				(
          {'''feature-extraction''': EfficientNetModel, '''image-classification''': EfficientNetForImageClassification}
          if is_torch_available()
          else {}
      )

      __magic_name__     :					int             =				False
      __magic_name__     :					Dict             =				False
      __magic_name__     :					Dict             =				False
      __magic_name__     :					Union[str, Any]             =				False
      __magic_name__     :					Optional[int]             =				False






      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     EfficientNetModelTester(self					)
           a_    :       Union[str, Any]    	=     ConfigTester(
               self	,	config_class=lowercase__	,	has_text_modality=lowercase__	,	hidden_size=37					)






      def        lowercase_	(   self      :     List[str]					):


           '''simple docstring'''

           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        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           return






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


           '''simple docstring'''

           pass






      @unittest.skip(reason="""EfficientNet does not support input and output embeddings"""					)
      def        lowercase_	(   self      :     Optional[Any]					):


           '''simple docstring'''

           pass






      @unittest.skip(reason="""EfficientNet does not use feedforward chunking"""					)
      def        lowercase_	(   self      :     str					):


           '''simple docstring'''

           pass






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


           '''simple docstring'''

           a_	,    a_    :       Dict    	=     self.model_tester.prepare_config_and_inputs_for_common()

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

                a_    :       Dict    	=     ["""pixel_values"""]
                self.assertListEqual(arg_names[:1]	,	lowercase__					)






      def        lowercase_	(   self      :     Optional[int]					):


           '''simple docstring'''

           a_    :       Tuple    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*lowercase__					)






      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           def check_hidden_states_output(lowercase__      :     Optional[int]	,	lowercase__      :     List[Any]	,	lowercase__      :     Tuple					):
                a_    :       str    	=     model_class(lowercase__					)
                model.to(lowercase__					)
                model.eval()

                with torch.no_grad():
                     a_    :       Tuple    	=     model(**self._prepare_for_class(lowercase__	,	lowercase__					)					)

                a_    :       Tuple    	=     outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
                a_    :       Tuple    	=     sum(config.num_block_repeats					) * 4
                self.assertEqual(len(lowercase__					)	,	lowercase__					)

                # 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]	,	)

           a_	,    a_    :       Any    	=     self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                a_    :       Any    	=     True
                check_hidden_states_output(lowercase__	,	lowercase__	,	lowercase__					)

                # check that output_hidden_states also work using config
                del inputs_dict["output_hidden_states"]
                a_    :       Any    	=     True

                check_hidden_states_output(lowercase__	,	lowercase__	,	lowercase__					)






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


           '''simple docstring'''

           a_    :       Optional[int]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*lowercase__					)






      @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""					)
      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           pass






      @slow
      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                a_    :       List[str]    	=     EfficientNetModel.from_pretrained(lowercase__					)
                self.assertIsNotNone(lowercase__					)






      @is_pipeline_test
      @require_vision
      @slow
      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           super().test_pipeline_image_classification()



def    _SCREAMING_SNAKE_CASE    (			):




     """simple docstring"""


     a_    :       List[str]    	=     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
     return image







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






      @cached_property
      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           return AutoImageProcessor.from_pretrained("""google/efficientnet-b7"""					) if is_vision_available() else None






      @slow
      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

           a_    :       Optional[Any]    	=     EfficientNetForImageClassification.from_pretrained("""google/efficientnet-b7"""					).to(lowercase__					)

           a_    :       Any    	=     self.default_image_processor
           a_    :       List[str]    	=     prepare_img()
           a_    :       str    	=     image_processor(images=lowercase__	,	return_tensors="""pt"""					).to(lowercase__					)

           # forward pass
           with torch.no_grad():
                a_    :       Tuple    	=     model(**lowercase__					)

           # verify the logits
           a_    :       Dict    	=     torch.Size((1, 1000)					)
           self.assertEqual(outputs.logits.shape	,	lowercase__					)

           a_    :       List[Any]    	=     torch.tensor([0.0001, 0.0002, 0.0002]					).to(lowercase__					)
           self.assertTrue(torch.allclose(outputs.logits[0, :3]	,	lowercase__	,	atol=1e-4					)					)
