"""simple docstring"""






import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
       import torch

       from transformers import (
           MODEL_FOR_PRETRAINING_MAPPING,
           AlbertForMaskedLM,
           AlbertForMultipleChoice,
           AlbertForPreTraining,
           AlbertForQuestionAnswering,
           AlbertForSequenceClassification,
           AlbertForTokenClassification,
           AlbertModel,
       )
       from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST


class     UpperCAmelCase						:



    """simple docstring"""

    def __init__(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase=13    ,			_UpperCAmelCase=7    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=99    ,			_UpperCAmelCase=16    ,			_UpperCAmelCase=36    ,			_UpperCAmelCase=6    ,			_UpperCAmelCase=6    ,			_UpperCAmelCase=6    ,			_UpperCAmelCase=37    ,			_UpperCAmelCase="gelu"    ,			_UpperCAmelCase=0.1    ,			_UpperCAmelCase=0.1    ,			_UpperCAmelCase=512    ,			_UpperCAmelCase=16    ,			_UpperCAmelCase=2    ,			_UpperCAmelCase=0.02    ,			_UpperCAmelCase=3    ,			_UpperCAmelCase=4    ,			_UpperCAmelCase=None    ,			):
       lowercase__:   int					=      parent
       lowercase__:   str					=      batch_size
       lowercase__:   List[Any]					=      seq_length
       lowercase__:   Optional[Any]					=      is_training
       lowercase__:   Tuple					=      use_input_mask
       lowercase__:   str					=      use_token_type_ids
       lowercase__:   List[str]					=      use_labels
       lowercase__:   Union[str, Any]					=      vocab_size
       lowercase__:   List[str]					=      embedding_size
       lowercase__:   Union[str, Any]					=      hidden_size
       lowercase__:   Optional[int]					=      num_hidden_layers
       lowercase__:   str					=      num_hidden_groups
       lowercase__:   List[str]					=      num_attention_heads
       lowercase__:   int					=      intermediate_size
       lowercase__:   Any					=      hidden_act
       lowercase__:   Tuple					=      hidden_dropout_prob
       lowercase__:   List[str]					=      attention_probs_dropout_prob
       lowercase__:   Union[str, Any]					=      max_position_embeddings
       lowercase__:   Union[str, Any]					=      type_vocab_size
       lowercase__:   Optional[int]					=      type_sequence_label_size
       lowercase__:   Any					=      initializer_range
       lowercase__:   str					=      num_labels
       lowercase__:   Union[str, Any]					=      num_choices
       lowercase__:   Union[str, Any]					=      scope






    def _snake_case			(   self							):
       lowercase__:   Any					=      ids_tensor([self.batch_size, self.seq_length]    ,			self.vocab_size							)

       lowercase__:   List[str]					=      None
       if self.use_input_mask:
          lowercase__:   str					=      random_attention_mask([self.batch_size, self.seq_length]							)

       lowercase__:   List[str]					=      None
       if self.use_token_type_ids:
          lowercase__:   List[Any]					=      ids_tensor([self.batch_size, self.seq_length]    ,			self.type_vocab_size							)

       lowercase__:   Tuple					=      None
       lowercase__:   Tuple					=      None
       lowercase__:   List[Any]					=      None
       if self.use_labels:
          lowercase__:   Tuple					=      ids_tensor([self.batch_size]    ,			self.type_sequence_label_size							)
          lowercase__:   Any					=      ids_tensor([self.batch_size, self.seq_length]    ,			self.num_labels							)
          lowercase__:   Any					=      ids_tensor([self.batch_size]    ,			self.num_choices							)

       lowercase__:   Optional[int]					=      self.get_config()

       return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






    def _snake_case			(   self							):
       return AlbertConfig(
           vocab_size=self.vocab_size    ,			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    ,			max_position_embeddings=self.max_position_embeddings    ,			type_vocab_size=self.type_vocab_size    ,			initializer_range=self.initializer_range    ,			num_hidden_groups=self.num_hidden_groups    ,			)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   str					=      AlbertModel(config=_UpperCAmelCase							)
       model.to(_UpperCAmelCase							)
       model.eval()
       lowercase__:   int					=      model(_UpperCAmelCase    ,			attention_mask=_UpperCAmelCase    ,			token_type_ids=_UpperCAmelCase							)
       lowercase__:   str					=      model(_UpperCAmelCase    ,			token_type_ids=_UpperCAmelCase							)
       lowercase__:   int					=      model(_UpperCAmelCase							)
       self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, self.seq_length, self.hidden_size)							)
       self.parent.assertEqual(result.pooler_output.shape    ,			(self.batch_size, self.hidden_size)							)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   Optional[Any]					=      AlbertForPreTraining(config=_UpperCAmelCase							)
       model.to(_UpperCAmelCase							)
       model.eval()
       lowercase__:   List[str]					=      model(
           _UpperCAmelCase    ,			attention_mask=_UpperCAmelCase    ,			token_type_ids=_UpperCAmelCase    ,			labels=_UpperCAmelCase    ,			sentence_order_label=_UpperCAmelCase    ,			)
       self.parent.assertEqual(result.prediction_logits.shape    ,			(self.batch_size, self.seq_length, self.vocab_size)							)
       self.parent.assertEqual(result.sop_logits.shape    ,			(self.batch_size, config.num_labels)							)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   str					=      AlbertForMaskedLM(config=_UpperCAmelCase							)
       model.to(_UpperCAmelCase							)
       model.eval()
       lowercase__:   Union[str, Any]					=      model(_UpperCAmelCase    ,			attention_mask=_UpperCAmelCase    ,			token_type_ids=_UpperCAmelCase    ,			labels=_UpperCAmelCase							)
       self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.vocab_size)							)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   Any					=      AlbertForQuestionAnswering(config=_UpperCAmelCase							)
       model.to(_UpperCAmelCase							)
       model.eval()
       lowercase__:   Dict					=      model(
           _UpperCAmelCase    ,			attention_mask=_UpperCAmelCase    ,			token_type_ids=_UpperCAmelCase    ,			start_positions=_UpperCAmelCase    ,			end_positions=_UpperCAmelCase    ,			)
       self.parent.assertEqual(result.start_logits.shape    ,			(self.batch_size, self.seq_length)							)
       self.parent.assertEqual(result.end_logits.shape    ,			(self.batch_size, self.seq_length)							)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   str					=      self.num_labels
       lowercase__:   Any					=      AlbertForSequenceClassification(_UpperCAmelCase							)
       model.to(_UpperCAmelCase							)
       model.eval()
       lowercase__:   int					=      model(_UpperCAmelCase    ,			attention_mask=_UpperCAmelCase    ,			token_type_ids=_UpperCAmelCase    ,			labels=_UpperCAmelCase							)
       self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels)							)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   List[Any]					=      self.num_labels
       lowercase__:   Dict					=      AlbertForTokenClassification(config=_UpperCAmelCase							)
       model.to(_UpperCAmelCase							)
       model.eval()
       lowercase__:   Any					=      model(_UpperCAmelCase    ,			attention_mask=_UpperCAmelCase    ,			token_type_ids=_UpperCAmelCase    ,			labels=_UpperCAmelCase							)
       self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.num_labels)							)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   Tuple					=      self.num_choices
       lowercase__:   List[Any]					=      AlbertForMultipleChoice(config=_UpperCAmelCase							)
       model.to(_UpperCAmelCase							)
       model.eval()
       lowercase__:   Any					=      input_ids.unsqueeze(1							).expand(-1    ,			self.num_choices    ,			-1							).contiguous()
       lowercase__:   Optional[int]					=      token_type_ids.unsqueeze(1							).expand(-1    ,			self.num_choices    ,			-1							).contiguous()
       lowercase__:   str					=      input_mask.unsqueeze(1							).expand(-1    ,			self.num_choices    ,			-1							).contiguous()
       lowercase__:   str					=      model(
           _UpperCAmelCase    ,			attention_mask=_UpperCAmelCase    ,			token_type_ids=_UpperCAmelCase    ,			labels=_UpperCAmelCase    ,			)
       self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_choices)							)






    def _snake_case			(   self							):
       lowercase__:   Dict					=      self.prepare_config_and_inputs()
       (
           (
           lowercase__
       ), (
           lowercase__
       ), (
           lowercase__
       ), (
           lowercase__
       ), (
           lowercase__
       ), (
           lowercase__
       ), (
           lowercase__
       ), 
       ):   Any					=      config_and_inputs
       lowercase__:   Optional[Any]					=      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict



@require_torch
class     UpperCAmelCase						(_UpperCAmelCase    ,_UpperCAmelCase    ,unittest.TestCase  ):



    """simple docstring"""

    _UpperCAmelCase	:List[Any]						    = (
        (
            AlbertModel,
            AlbertForPreTraining,
            AlbertForMaskedLM,
            AlbertForMultipleChoice,
            AlbertForSequenceClassification,
            AlbertForTokenClassification,
            AlbertForQuestionAnswering,
        )
        if is_torch_available()
        else ()
    )
    _UpperCAmelCase	:Any						    = (
        {
            "feature-extraction": AlbertModel,
            "fill-mask": AlbertForMaskedLM,
            "question-answering": AlbertForQuestionAnswering,
            "text-classification": AlbertForSequenceClassification,
            "token-classification": AlbertForTokenClassification,
            "zero-shot": AlbertForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    _UpperCAmelCase	:int						    = True






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase=False							):
       lowercase__:   int					=      super()._prepare_for_class(_UpperCAmelCase    ,			_UpperCAmelCase    ,			return_labels=_UpperCAmelCase							)

       if return_labels:
          if model_class in get_values(_UpperCAmelCase							):
             lowercase__:   str					=      torch.zeros(
                 (self.model_tester.batch_size, self.model_tester.seq_length)    ,			dtype=torch.long    ,			device=_UpperCAmelCase							)
             lowercase__:   List[str]					=      torch.zeros(
                 self.model_tester.batch_size    ,			dtype=torch.long    ,			device=_UpperCAmelCase							)
       return inputs_dict






    def _snake_case			(   self							):
       lowercase__:   Optional[Any]					=      AlbertModelTester(self							)
       lowercase__:   int					=      ConfigTester(self    ,			config_class=_UpperCAmelCase    ,			hidden_size=37							)






    def _snake_case			(   self							):
       self.config_tester.run_common_tests()






    def _snake_case			(   self							):
       lowercase__:   List[str]					=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Optional[Any]					=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_pretraining(*_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Optional[int]					=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Tuple					=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Optional[Any]					=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Optional[int]					=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Tuple					=      self.model_tester.prepare_config_and_inputs()
       for type in ["absolute", "relative_key", "relative_key_query"]:
          lowercase__:   Optional[Any]					=      type
          self.model_tester.create_and_check_model(*_UpperCAmelCase							)






    @slow
    def _snake_case			(   self							):
       for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          lowercase__:   Dict					=      AlbertModel.from_pretrained(_UpperCAmelCase							)
          self.assertIsNotNone(_UpperCAmelCase							)



@require_torch
class     UpperCAmelCase						(unittest.TestCase  ):



    """simple docstring"""

    @slow
    def _snake_case			(   self							):
       lowercase__:   Tuple					=      AlbertModel.from_pretrained('''albert-base-v2'''							)
       lowercase__:   List[Any]					=      torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]							)
       lowercase__:   Union[str, Any]					=      torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
       with torch.no_grad():
          lowercase__:   int					=      model(_UpperCAmelCase    ,			attention_mask=_UpperCAmelCase							)[0]
       lowercase__:   str					=      torch.Size((1, 11, 768)							)
       self.assertEqual(output.shape    ,			_UpperCAmelCase							)
       lowercase__:   int					=      torch.tensor(
           [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]]							)

       self.assertTrue(torch.allclose(output[:, 1:4, 1:4]    ,			_UpperCAmelCase    ,			atol=1e-4							)							)

"""simple docstring"""






from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import ResNetConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
       import tensorflow as tf

       from transformers import TFResNetForImageClassification, TFResNetModel
       from transformers.models.resnet.modeling_tf_resnet import TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from PIL import Image

       from transformers import AutoImageProcessor


class     UpperCAmelCase						:



    """simple docstring"""

    def __init__(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase=3    ,			_UpperCAmelCase=32    ,			_UpperCAmelCase=3    ,			_UpperCAmelCase=10    ,			_UpperCAmelCase=[10, 20, 30, 40]    ,			_UpperCAmelCase=[1, 1, 2, 1]    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase="relu"    ,			_UpperCAmelCase=3    ,			_UpperCAmelCase=None    ,			):
       lowercase__:   Optional[Any]					=      parent
       lowercase__:   Union[str, Any]					=      batch_size
       lowercase__:   int					=      image_size
       lowercase__:   Optional[Any]					=      num_channels
       lowercase__:   Optional[int]					=      embeddings_size
       lowercase__:   Dict					=      hidden_sizes
       lowercase__:   Union[str, Any]					=      depths
       lowercase__:   str					=      is_training
       lowercase__:   Optional[int]					=      use_labels
       lowercase__:   List[str]					=      hidden_act
       lowercase__:   Dict					=      num_labels
       lowercase__:   Any					=      scope
       lowercase__:   Optional[Any]					=      len(_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Union[str, Any]					=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

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

       lowercase__:   Optional[int]					=      self.get_config()

       return config, pixel_values, labels






    def _snake_case			(   self							):
       return ResNetConfig(
           num_channels=self.num_channels    ,			embeddings_size=self.embeddings_size    ,			hidden_sizes=self.hidden_sizes    ,			depths=self.depths    ,			hidden_act=self.hidden_act    ,			num_labels=self.num_labels    ,			image_size=self.image_size    ,			)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   Optional[Any]					=      TFResNetModel(config=_UpperCAmelCase							)
       lowercase__:   Dict					=      model(_UpperCAmelCase							)
       # expected last hidden states: B, C, H // 32, W // 32
       self.parent.assertEqual(
           result.last_hidden_state.shape    ,			(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)    ,			)






    def _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   str					=      self.num_labels
       lowercase__:   int					=      TFResNetForImageClassification(_UpperCAmelCase							)
       lowercase__:   Optional[Any]					=      model(_UpperCAmelCase    ,			labels=_UpperCAmelCase							)
       self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels)							)






    def _snake_case			(   self							):
       lowercase__:   int					=      self.prepare_config_and_inputs()
       lowercase__, lowercase__, lowercase__:   Optional[Any]					=      config_and_inputs
       lowercase__:   Union[str, Any]					=      {'''pixel_values''': pixel_values}
       return config, inputs_dict



@require_tf
class     UpperCAmelCase						(_UpperCAmelCase    ,_UpperCAmelCase    ,unittest.TestCase  ):



    """simple docstring"""

    _UpperCAmelCase	:Any						    = (TFResNetModel, TFResNetForImageClassification) if is_tf_available() else ()
    _UpperCAmelCase	:List[str]						    = (
        {"feature-extraction": TFResNetModel, "image-classification": TFResNetForImageClassification}
        if is_tf_available()
        else {}
    )

    _UpperCAmelCase	:Any						    = False
    _UpperCAmelCase	:List[str]						    = False
    _UpperCAmelCase	:Optional[Any]						    = False
    _UpperCAmelCase	:Tuple						    = False
    _UpperCAmelCase	:List[Any]						    = False






    def _snake_case			(   self							):
       lowercase__:   Union[str, Any]					=      TFResNetModelTester(self							)
       lowercase__:   Optional[int]					=      ConfigTester(self    ,			config_class=_UpperCAmelCase    ,			has_text_modality=_UpperCAmelCase							)






    def _snake_case			(   self							):
       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 _snake_case			(   self							):
       return






    @unittest.skip(reason='''ResNet does not use inputs_embeds'''							)
    def _snake_case			(   self							):
       pass






    @unittest.skip(reason='''ResNet does not support input and output embeddings'''							)
    def _snake_case			(   self							):
       pass






    def _snake_case			(   self							):
       lowercase__, lowercase__:   int					=      self.model_tester.prepare_config_and_inputs_for_common()

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

          lowercase__:   Optional[Any]					=      ['''pixel_values''']
          self.assertListEqual(arg_names[:1]    ,			_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Any					=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_UpperCAmelCase							)






    def _snake_case			(   self							):
       def check_hidden_states_output(_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
          lowercase__:   Union[str, Any]					=      model_class(_UpperCAmelCase							)
          lowercase__:   List[Any]					=      model(**self._prepare_for_class(_UpperCAmelCase    ,			_UpperCAmelCase							)							)

          lowercase__:   Union[str, Any]					=      outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

          lowercase__:   Tuple					=      self.model_tester.num_stages
          self.assertEqual(len(_UpperCAmelCase							)    ,			expected_num_stages + 1							)

          # ResNet'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 // 4, self.model_tester.image_size // 4]    ,			)

       lowercase__, lowercase__:   Optional[Any]					=      self.model_tester.prepare_config_and_inputs_for_common()
       lowercase__:   Union[str, Any]					=      ['''basic''', '''bottleneck''']
       for model_class in self.all_model_classes:
          for layer_type in layers_type:
             lowercase__:   Tuple					=      layer_type
             lowercase__:   Any					=      True
             check_hidden_states_output(_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							)

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             lowercase__:   List[str]					=      True

             check_hidden_states_output(_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Optional[int]					=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*_UpperCAmelCase							)






    @slow
    def _snake_case			(   self							):
       for model_name in TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          lowercase__:   Dict					=      TFResNetModel.from_pretrained(_UpperCAmelCase							)
          self.assertIsNotNone(_UpperCAmelCase							)



def SCREAMING_SNAKE_CASE__			(   )  ->  List[Any]:
   lowercase__:   List[Any]					=      Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''' )
   return image




@require_tf
@require_vision
class     UpperCAmelCase						(unittest.TestCase  ):



    """simple docstring"""

    @cached_property
    def _snake_case			(   self							):
       return (
           AutoImageProcessor.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]							)
           if is_vision_available()
           else None
       )






    @slow
    def _snake_case			(   self							):
       lowercase__:   Tuple					=      TFResNetForImageClassification.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]							)

       lowercase__:   Any					=      self.default_image_processor
       lowercase__:   List[Any]					=      prepare_img()
       lowercase__:   List[Any]					=      image_processor(images=_UpperCAmelCase    ,			return_tensors='''tf'''							)

       # forward pass
       lowercase__:   Dict					=      model(**_UpperCAmelCase							)

       # verify the logits
       lowercase__:   int					=      tf.TensorShape((1, 1000)							)
       self.assertEqual(outputs.logits.shape    ,			_UpperCAmelCase							)

       lowercase__:   Dict					=      tf.constant([-11.1_069, -9.7_877, -8.3_777]							)

       self.assertTrue(np.allclose(outputs.logits[0, :3].numpy()    ,			_UpperCAmelCase    ,			atol=1e-4							)							)
