






import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, 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,
					    MobileBertForMaskedLM,
					    MobileBertForMultipleChoice,
					    MobileBertForNextSentencePrediction,
					    MobileBertForPreTraining,
					    MobileBertForQuestionAnswering,
					    MobileBertForSequenceClassification,
					    MobileBertForTokenClassification,
					    MobileBertModel,
					)


class       __SCREAMING_SNAKE_CASE   :






						def __init__(		self       ,  _UpperCamelCase       ,  _UpperCamelCase=13       ,  _UpperCamelCase=7       ,  _UpperCamelCase=True       ,  _UpperCamelCase=True       ,  _UpperCamelCase=True       ,  _UpperCamelCase=True       ,  _UpperCamelCase=99       ,  _UpperCamelCase=64       ,  _UpperCamelCase=32       ,  _UpperCamelCase=5       ,  _UpperCamelCase=4       ,  _UpperCamelCase=37       ,  _UpperCamelCase="gelu"       ,  _UpperCamelCase=0.1       ,  _UpperCamelCase=0.1       ,  _UpperCamelCase=5_12       ,  _UpperCamelCase=16       ,  _UpperCamelCase=2       ,  _UpperCamelCase=0.02       ,  _UpperCamelCase=3       ,  _UpperCamelCase=4       ,  _UpperCamelCase=None       ,  ):






												"""simple docstring"""
												lowerCAmelCase__        =  parent
												lowerCAmelCase__        =  batch_size
												lowerCAmelCase__        =  seq_length
												lowerCAmelCase__        =  is_training
												lowerCAmelCase__        =  use_input_mask
												lowerCAmelCase__        =  use_token_type_ids
												lowerCAmelCase__        =  use_labels
												lowerCAmelCase__        =  vocab_size
												lowerCAmelCase__        =  hidden_size
												lowerCAmelCase__        =  embedding_size
												lowerCAmelCase__        =  num_hidden_layers
												lowerCAmelCase__        =  num_attention_heads
												lowerCAmelCase__        =  intermediate_size
												lowerCAmelCase__        =  hidden_act
												lowerCAmelCase__        =  hidden_dropout_prob
												lowerCAmelCase__        =  attention_probs_dropout_prob
												lowerCAmelCase__        =  max_position_embeddings
												lowerCAmelCase__        =  type_vocab_size
												lowerCAmelCase__        =  type_sequence_label_size
												lowerCAmelCase__        =  initializer_range
												lowerCAmelCase__        =  num_labels
												lowerCAmelCase__        =  num_choices
												lowerCAmelCase__        =  scope






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size				)

												lowerCAmelCase__        =  None
												if self.use_input_mask:
																		lowerCAmelCase__        =  random_attention_mask([self.batch_size, self.seq_length]				)

												lowerCAmelCase__        =  None
												if self.use_token_type_ids:
																		lowerCAmelCase__        =  ids_tensor([self.batch_size, self.seq_length]       ,  self.type_vocab_size				)

												lowerCAmelCase__        =  None
												lowerCAmelCase__        =  None
												lowerCAmelCase__        =  None
												if self.use_labels:
																		lowerCAmelCase__        =  ids_tensor([self.batch_size]       ,  self.type_sequence_label_size				)
																		lowerCAmelCase__        =  ids_tensor([self.batch_size, self.seq_length]       ,  self.num_labels				)
																		lowerCAmelCase__        =  ids_tensor([self.batch_size]       ,  self.num_choices				)

												lowerCAmelCase__        =  self.get_config()

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






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												return MobileBertConfig(
												    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       ,  embedding_size=self.embedding_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       ,  is_decoder=_a       ,  initializer_range=self.initializer_range       ,  )






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  MobileBertModel(config=_a				)
												model.to(_a				)
												model.eval()
												lowerCAmelCase__        =  model(_a       ,  attention_mask=_a       ,  token_type_ids=_a				)
												lowerCAmelCase__        =  model(_a       ,  token_type_ids=_a				)
												lowerCAmelCase__        =  model(_a				)

												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  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  MobileBertForMaskedLM(config=_a				)
												model.to(_a				)
												model.eval()
												lowerCAmelCase__        =  model(_a       ,  attention_mask=_a       ,  token_type_ids=_a       ,  labels=_a				)
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size)				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  MobileBertForNextSentencePrediction(config=_a				)
												model.to(_a				)
												model.eval()
												lowerCAmelCase__        =  model(
												    _a       ,  attention_mask=_a       ,  token_type_ids=_a       ,  labels=_a       ,  )
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, 2)				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  MobileBertForPreTraining(config=_a				)
												model.to(_a				)
												model.eval()
												lowerCAmelCase__        =  model(
												    _a       ,  attention_mask=_a       ,  token_type_ids=_a       ,  labels=_a       ,  next_sentence_label=_a       ,  )
												self.parent.assertEqual(result.prediction_logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size)				)
												self.parent.assertEqual(result.seq_relationship_logits.shape       ,  (self.batch_size, 2)				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  MobileBertForQuestionAnswering(config=_a				)
												model.to(_a				)
												model.eval()
												lowerCAmelCase__        =  model(
												    _a       ,  attention_mask=_a       ,  token_type_ids=_a       ,  start_positions=_a       ,  end_positions=_a       ,  )
												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  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.num_labels
												lowerCAmelCase__        =  MobileBertForSequenceClassification(_a				)
												model.to(_a				)
												model.eval()
												lowerCAmelCase__        =  model(_a       ,  attention_mask=_a       ,  token_type_ids=_a       ,  labels=_a				)
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_labels)				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.num_labels
												lowerCAmelCase__        =  MobileBertForTokenClassification(config=_a				)
												model.to(_a				)
												model.eval()
												lowerCAmelCase__        =  model(_a       ,  attention_mask=_a       ,  token_type_ids=_a       ,  labels=_a				)
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.num_labels)				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.num_choices
												lowerCAmelCase__        =  MobileBertForMultipleChoice(config=_a				)
												model.to(_a				)
												model.eval()
												lowerCAmelCase__        =  input_ids.unsqueeze(1				).expand(-1       ,  self.num_choices       ,  -1				).contiguous()
												lowerCAmelCase__        =  token_type_ids.unsqueeze(1				).expand(-1       ,  self.num_choices       ,  -1				).contiguous()
												lowerCAmelCase__        =  input_mask.unsqueeze(1				).expand(-1       ,  self.num_choices       ,  -1				).contiguous()
												lowerCAmelCase__        =  model(
												    _a       ,  attention_mask=_a       ,  token_type_ids=_a       ,  labels=_a       ,  )
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_choices)				)







						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.prepare_config_and_inputs()
												(
												    lowerCAmelCase__ 
												)        =  config_and_inputs
												lowerCAmelCase__        =  {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
												return config, inputs_dict




@require_torch
class       __SCREAMING_SNAKE_CASE   (				__lowercase						,   __lowercase						,   unittest.TestCase):
						_SCREAMING_SNAKE_CASE		:    Any						=   (
						    (
						        MobileBertModel,
						        MobileBertForMaskedLM,
						        MobileBertForMultipleChoice,
						        MobileBertForNextSentencePrediction,
						        MobileBertForPreTraining,
						        MobileBertForQuestionAnswering,
						        MobileBertForSequenceClassification,
						        MobileBertForTokenClassification,
						    )
						    if is_torch_available()
						    else ()
						)
						_SCREAMING_SNAKE_CASE		:    Optional[int]						=   (
						    {
						        "feature-extraction": MobileBertModel,
						        "fill-mask": MobileBertForMaskedLM,
						        "question-answering": MobileBertForQuestionAnswering,
						        "text-classification": MobileBertForSequenceClassification,
						        "token-classification": MobileBertForTokenClassification,
						        "zero-shot": MobileBertForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						_SCREAMING_SNAKE_CASE		:    int						=   True






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase=False				):






												"""simple docstring"""
												lowerCAmelCase__        =  super()._prepare_for_class(_a       ,  _a       ,  return_labels=_a				)

												if return_labels:
																		if model_class in get_values(_a				):
																								lowerCAmelCase__        =  torch.zeros(
																								    (self.model_tester.batch_size, self.model_tester.seq_length)       ,  dtype=torch.long       ,  device=_a				)
																								lowerCAmelCase__        =  torch.zeros(
																								    self.model_tester.batch_size       ,  dtype=torch.long       ,  device=_a				)
												return inputs_dict






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  MobileBertModelTester(self				)
												lowerCAmelCase__        =  ConfigTester(self       ,  config_class=_a       ,  hidden_size=37				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												self.config_tester.run_common_tests()






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mobilebert_model(*_a				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mobilebert_for_masked_lm(*_a				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mobilebert_for_multiple_choice(*_a				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*_a				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mobilebert_for_pretraining(*_a				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mobilebert_for_question_answering(*_a				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mobilebert_for_sequence_classification(*_a				)







						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mobilebert_for_token_classification(*_a				)







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

						"""simple docstring"""



						return torch.tensor(
						    __a      ,    dtype=torch.long      ,    device=__a      ,    )


__snake_case      :      Optional[Any]             =   1e-3


@require_torch
@require_sentencepiece
@require_tokenizers
class       __SCREAMING_SNAKE_CASE   (				unittest.TestCase):






						@slow
						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  MobileBertModel.from_pretrained('google/mobilebert-uncased'				).to(_a				)
												lowerCAmelCase__        =  _long_tensor([[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]]				)
												with torch.no_grad():
																		lowerCAmelCase__        =  model(_a				)[0]
												lowerCAmelCase__        =  torch.Size((1, 9, 5_12)				)
												self.assertEqual(output.shape       ,  _a				)
												lowerCAmelCase__        =  torch.tensor(
												    [
												        [
												            [-2.473_6526E07, 8.269_1656E04, 1.652_1838E05],
												            [-5.754_1704E-01, 3.905_6022E00, 4.401_1507E00],
												            [2.604_7359E00, 1.567_7652E00, -1.732_4188E-01],
												        ]
												    ]       ,  device=_a       ,  )

												# MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
												# ~1 difference, it's therefore not a good idea to measure using addition.
												# Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
												# result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
												lowerCAmelCase__        =  torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE				)
												lowerCAmelCase__        =  torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE				)

												self.assertTrue(lower_bound and upper_bound				)













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       __SCREAMING_SNAKE_CASE   :






						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       ,  ):






												"""simple docstring"""
												lowerCAmelCase__        =  parent
												lowerCAmelCase__        =  batch_size
												lowerCAmelCase__        =  image_size
												lowerCAmelCase__        =  num_channels
												lowerCAmelCase__        =  embeddings_size
												lowerCAmelCase__        =  hidden_sizes
												lowerCAmelCase__        =  depths
												lowerCAmelCase__        =  is_training
												lowerCAmelCase__        =  use_labels
												lowerCAmelCase__        =  hidden_act
												lowerCAmelCase__        =  num_labels
												lowerCAmelCase__        =  scope
												lowerCAmelCase__        =  len(_UpperCamelCase				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

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

												lowerCAmelCase__        =  self.get_config()

												return config, pixel_values, labels






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												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  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  TFResNetModel(config=_UpperCamelCase				)
												lowerCAmelCase__        =  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  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.num_labels
												lowerCAmelCase__        =  TFResNetForImageClassification(_UpperCamelCase				)
												lowerCAmelCase__        =  model(_UpperCamelCase       ,  labels=_UpperCamelCase				)
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_labels)				)







						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.prepare_config_and_inputs()
												lowerCAmelCase__  ,    lowerCAmelCase__  ,    lowerCAmelCase__        =  config_and_inputs
												lowerCAmelCase__        =  {'pixel_values': pixel_values}
												return config, inputs_dict




@require_tf
class       __SCREAMING_SNAKE_CASE   (				__lowercase						,   __lowercase						,   unittest.TestCase):
						_SCREAMING_SNAKE_CASE		:    Any						=   (TFResNetModel, TFResNetForImageClassification) if is_tf_available() else ()
						_SCREAMING_SNAKE_CASE		:    List[str]						=   (
						    {'''feature-extraction''': TFResNetModel, '''image-classification''': TFResNetForImageClassification}
						    if is_tf_available()
						    else {}
						)

						_SCREAMING_SNAKE_CASE		:    Union[str, Any]						=   False
						_SCREAMING_SNAKE_CASE		:    int						=   False
						_SCREAMING_SNAKE_CASE		:    Optional[int]						=   False
						_SCREAMING_SNAKE_CASE		:    List[str]						=   False
						_SCREAMING_SNAKE_CASE		:    Optional[Any]						=   False






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  TFResNetModelTester(self				)
												lowerCAmelCase__        =  ConfigTester(self       ,  config_class=_UpperCamelCase       ,  has_text_modality=_UpperCamelCase				)






						def  UpperCamelCase__ (		self				):






												"""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  UpperCamelCase__ (		self				):






												"""simple docstring"""
												return






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






												"""simple docstring"""
												pass






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






												"""simple docstring"""
												pass






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__  ,    lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs_for_common()

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

																		lowerCAmelCase__        =  ['pixel_values']
																		self.assertListEqual(arg_names[:1]       ,  _UpperCamelCase				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*_UpperCamelCase				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												def check_hidden_states_output(_UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				):
																		lowerCAmelCase__        =  model_class(_UpperCamelCase				)
																		lowerCAmelCase__        =  model(**self._prepare_for_class(_UpperCamelCase       ,  _UpperCamelCase				)				)

																		lowerCAmelCase__        =  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																		lowerCAmelCase__        =  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]       ,  )

												lowerCAmelCase__  ,    lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs_for_common()
												lowerCAmelCase__        =  ['basic', 'bottleneck']
												for model_class in self.all_model_classes:
																		for layer_type in layers_type:
																								lowerCAmelCase__        =  layer_type
																								lowerCAmelCase__        =  True
																								check_hidden_states_output(_UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				)

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

																								check_hidden_states_output(_UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_image_classification(*_UpperCamelCase				)







						@slow
						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												for model_name in TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		lowerCAmelCase__        =  TFResNetModel.from_pretrained(_UpperCamelCase				)
																		self.assertIsNotNone(_UpperCamelCase				)







def 		_UpperCamelCase				(      )					->				List[str]:

						"""simple docstring"""



						lowerCAmelCase__        =  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
						return image


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






						@cached_property
						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												return (
												    AutoImageProcessor.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]				)
												    if is_vision_available()
												    else None
												)







						@slow
						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  TFResNetForImageClassification.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]				)

												lowerCAmelCase__        =  self.default_image_processor
												lowerCAmelCase__        =  prepare_img()
												lowerCAmelCase__        =  image_processor(images=_UpperCamelCase       ,  return_tensors='tf'				)

												# forward pass
												lowerCAmelCase__        =  model(**_UpperCamelCase				)

												# verify the logits
												lowerCAmelCase__        =  tf.TensorShape((1, 10_00)				)
												self.assertEqual(outputs.logits.shape       ,  _UpperCamelCase				)

												lowerCAmelCase__        =  tf.constant([-11.10_69, -9.78_77, -8.37_77]				)

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





