import unittest

from transformers import (
    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    Pipeline,
    ZeroShotClassificationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_tf, require_torch, slow

from .test_pipelines_common import ANY


# These 2 model types require different inputs than those of the usual text models.
_snake_case								=  {'''LayoutLMv2Config''', '''LayoutLMv3Config'''}




@is_pipeline_test
class     _snake_case  (  unittest.TestCase ):
					lowerCamelCase__:						int     =   MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
					lowerCamelCase__:						Tuple     =   TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

					if model_mapping is not None:
										lowerCamelCase__:						Union[str, Any]     =   {config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
					if tf_model_mapping is not None:
										lowerCamelCase__:						List[str]     =   {
										    config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
										}
					def       _lowerCamelCase       (     self: Any		,     __lowerCamelCase: Dict		,     __lowerCamelCase: Optional[Any]		,     __lowerCamelCase: Optional[Any]   )			-> List[str]:
												__UpperCAmelCase  :	Dict   			=      ZeroShotClassificationPipeline(
												    model=__lowerCamelCase		,     tokenizer=__lowerCamelCase		,     candidate_labels=["polics", "health"]   )
												return classifier, ["Who are you voting for in 2020?", "My stomach hurts."]
					def       _lowerCamelCase       (     self: Tuple		,     __lowerCamelCase: Tuple		,     __lowerCamelCase: str   )			-> Optional[int]:
												__UpperCAmelCase  :	Optional[int]   			=      classifier("Who are you voting for in 2020?"		,     candidate_labels="politics"   )
												self.assertEqual(__lowerCamelCase		,     {"sequence": ANY(__lowerCamelCase   ), "labels": [ANY(__lowerCamelCase   )], "scores": [ANY(__lowerCamelCase   )]}   )

												# No kwarg
												__UpperCAmelCase  :	Optional[Any]   			=      classifier("Who are you voting for in 2020?"		,     ["politics"]   )
												self.assertEqual(__lowerCamelCase		,     {"sequence": ANY(__lowerCamelCase   ), "labels": [ANY(__lowerCamelCase   )], "scores": [ANY(__lowerCamelCase   )]}   )

												__UpperCAmelCase  :	Optional[int]   			=      classifier("Who are you voting for in 2020?"		,     candidate_labels=["politics"]   )
												self.assertEqual(__lowerCamelCase		,     {"sequence": ANY(__lowerCamelCase   ), "labels": [ANY(__lowerCamelCase   )], "scores": [ANY(__lowerCamelCase   )]}   )

												__UpperCAmelCase  :	Any   			=      classifier("Who are you voting for in 2020?"		,     candidate_labels="politics, public health"   )
												self.assertEqual(
												    __lowerCamelCase		,     {"sequence": ANY(__lowerCamelCase   ), "labels": [ANY(__lowerCamelCase   ), ANY(__lowerCamelCase   )], "scores": [ANY(__lowerCamelCase   ), ANY(__lowerCamelCase   )]}   )
												self.assertAlmostEqual(sum(nested_simplify(outputs["scores"]   )   )		,     1.0   )

												__UpperCAmelCase  :	int   			=      classifier("Who are you voting for in 2020?"		,     candidate_labels=["politics", "public health"]   )
												self.assertEqual(
												    __lowerCamelCase		,     {"sequence": ANY(__lowerCamelCase   ), "labels": [ANY(__lowerCamelCase   ), ANY(__lowerCamelCase   )], "scores": [ANY(__lowerCamelCase   ), ANY(__lowerCamelCase   )]}   )
												self.assertAlmostEqual(sum(nested_simplify(outputs["scores"]   )   )		,     1.0   )

												__UpperCAmelCase  :	Tuple   			=      classifier(
												    "Who are you voting for in 2020?"		,     candidate_labels="politics"		,     hypothesis_template="This text is about {}"   )
												self.assertEqual(__lowerCamelCase		,     {"sequence": ANY(__lowerCamelCase   ), "labels": [ANY(__lowerCamelCase   )], "scores": [ANY(__lowerCamelCase   )]}   )

												# https://github.com/huggingface/transformers/issues/13846
												__UpperCAmelCase  :	List[str]   			=      classifier(["I am happy"]		,     ["positive", "negative"]   )
												self.assertEqual(
												    __lowerCamelCase		,     [
												        {"sequence": ANY(__lowerCamelCase   ), "labels": [ANY(__lowerCamelCase   ), ANY(__lowerCamelCase   )], "scores": [ANY(__lowerCamelCase   ), ANY(__lowerCamelCase   )]}
												        for i in range(1   )
												    ]		,     )
												__UpperCAmelCase  :	List[Any]   			=      classifier(["I am happy", "I am sad"]		,     ["positive", "negative"]   )
												self.assertEqual(
												    __lowerCamelCase		,     [
												        {"sequence": ANY(__lowerCamelCase   ), "labels": [ANY(__lowerCamelCase   ), ANY(__lowerCamelCase   )], "scores": [ANY(__lowerCamelCase   ), ANY(__lowerCamelCase   )]}
												        for i in range(2   )
												    ]		,     )

												with self.assertRaises(__lowerCamelCase   ):
																			classifier(""		,     candidate_labels="politics"   )

												with self.assertRaises(__lowerCamelCase   ):
																			classifier(__lowerCamelCase		,     candidate_labels="politics"   )

												with self.assertRaises(__lowerCamelCase   ):
																			classifier("Who are you voting for in 2020?"		,     candidate_labels=""   )

												with self.assertRaises(__lowerCamelCase   ):
																			classifier("Who are you voting for in 2020?"		,     candidate_labels=__lowerCamelCase   )

												with self.assertRaises(__lowerCamelCase   ):
																			classifier(
																			    "Who are you voting for in 2020?"		,     candidate_labels="politics"		,     hypothesis_template="Not formatting template"		,     )

												with self.assertRaises(__lowerCamelCase   ):
																			classifier(
																			    "Who are you voting for in 2020?"		,     candidate_labels="politics"		,     hypothesis_template=__lowerCamelCase		,     )

												self.run_entailment_id(__lowerCamelCase   )
					def       _lowerCamelCase       (     self: List[Any]		,     __lowerCamelCase: Optional[int]   )			-> Optional[int]:
												__UpperCAmelCase  :	Dict   			=      zero_shot_classifier.model.config
												__UpperCAmelCase  :	List[Any]   			=      config.labelaid
												__UpperCAmelCase  :	str   			=      zero_shot_classifier.entailment_id

												__UpperCAmelCase  :	Dict   			=      {"LABEL_0": 0, "LABEL_1": 1, "LABEL_2": 2}
												self.assertEqual(zero_shot_classifier.entailment_id		,     -1   )

												__UpperCAmelCase  :	Any   			=      {"entailment": 0, "neutral": 1, "contradiction": 2}
												self.assertEqual(zero_shot_classifier.entailment_id		,     0   )

												__UpperCAmelCase  :	Dict   			=      {"ENTAIL": 0, "NON-ENTAIL": 1}
												self.assertEqual(zero_shot_classifier.entailment_id		,     0   )

												__UpperCAmelCase  :	str   			=      {"ENTAIL": 2, "NEUTRAL": 1, "CONTR": 0}
												self.assertEqual(zero_shot_classifier.entailment_id		,     2   )

												__UpperCAmelCase  :	int   			=      original_labelaid
												self.assertEqual(__lowerCamelCase		,     zero_shot_classifier.entailment_id   )
					@require_torch
					def       _lowerCamelCase       (     self: Optional[Any]   )			-> List[Any]:
												__UpperCAmelCase  :	Optional[int]   			=      pipeline(
												    "zero-shot-classification"		,     model="sshleifer/tiny-distilbert-base-cased-distilled-squad"		,     framework="pt"		,     )
												# There was a regression in 4.10 for this
												# Adding a test so we don't make the mistake again.
												# https://github.com/huggingface/transformers/issues/13381#issuecomment-912343499
												zero_shot_classifier(
												    "Who are you voting for in 2020?" * 1_00		,     candidate_labels=["politics", "public health", "science"]   )
					@require_torch
					def       _lowerCamelCase       (     self: str   )			-> Any:
												__UpperCAmelCase  :	int   			=      pipeline(
												    "zero-shot-classification"		,     model="sshleifer/tiny-distilbert-base-cased-distilled-squad"		,     framework="pt"		,     )
												__UpperCAmelCase  :	Union[str, Any]   			=      zero_shot_classifier(
												    "Who are you voting for in 2020?"		,     candidate_labels=["politics", "public health", "science"]   )

												self.assertEqual(
												    nested_simplify(__lowerCamelCase   )		,     {
												        "sequence": "Who are you voting for in 2020?",
												        "labels": ["science", "public health", "politics"],
												        "scores": [0.3_33, 0.3_33, 0.3_33],
												    }		,     )
					@require_tf
					def       _lowerCamelCase       (     self: Tuple   )			-> Tuple:
												__UpperCAmelCase  :	List[Any]   			=      pipeline(
												    "zero-shot-classification"		,     model="sshleifer/tiny-distilbert-base-cased-distilled-squad"		,     framework="tf"		,     )
												__UpperCAmelCase  :	Tuple   			=      zero_shot_classifier(
												    "Who are you voting for in 2020?"		,     candidate_labels=["politics", "public health", "science"]   )

												self.assertEqual(
												    nested_simplify(__lowerCamelCase   )		,     {
												        "sequence": "Who are you voting for in 2020?",
												        "labels": ["science", "public health", "politics"],
												        "scores": [0.3_33, 0.3_33, 0.3_33],
												    }		,     )
					@slow
					@require_torch
					def       _lowerCamelCase       (     self: Any   )			-> List[str]:
												__UpperCAmelCase  :	List[str]   			=      pipeline("zero-shot-classification"		,     model="roberta-large-mnli"		,     framework="pt"   )
												__UpperCAmelCase  :	Dict   			=      zero_shot_classifier(
												    "Who are you voting for in 2020?"		,     candidate_labels=["politics", "public health", "science"]   )

												self.assertEqual(
												    nested_simplify(__lowerCamelCase   )		,     {
												        "sequence": "Who are you voting for in 2020?",
												        "labels": ["politics", "public health", "science"],
												        "scores": [0.9_76, 0.0_15, 0.0_09],
												    }		,     )
												__UpperCAmelCase  :	Optional[Any]   			=      zero_shot_classifier(
												    "The dominant sequence transduction models are based on complex recurrent or convolutional neural networks"
												    " in an encoder-decoder configuration. The best performing models also connect the encoder and decoder"
												    " through an attention mechanism. We propose a new simple network architecture, the Transformer, based"
												    " solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two"
												    " machine translation tasks show these models to be superior in quality while being more parallelizable"
												    " and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014"
												    " English-to-German translation task, improving over the existing best results, including ensembles by"
												    " over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new"
												    " single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small"
												    " fraction of the training costs of the best models from the literature. We show that the Transformer"
												    " generalizes well to other tasks by applying it successfully to English constituency parsing both with"
												    " large and limited training data."		,     candidate_labels=["machine learning", "statistics", "translation", "vision"]		,     multi_label=__lowerCamelCase		,     )
												self.assertEqual(
												    nested_simplify(__lowerCamelCase   )		,     {
												        "sequence": (
												            "The dominant sequence transduction models are based on complex recurrent or convolutional neural"
												            " networks in an encoder-decoder configuration. The best performing models also connect the"
												            " encoder and decoder through an attention mechanism. We propose a new simple network"
												            " architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence"
												            " and convolutions entirely. Experiments on two machine translation tasks show these models to be"
												            " superior in quality while being more parallelizable and requiring significantly less time to"
												            " train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task,"
												            " improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014"
												            " English-to-French translation task, our model establishes a new single-model state-of-the-art"
												            " BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training"
												            " costs of the best models from the literature. We show that the Transformer generalizes well to"
												            " other tasks by applying it successfully to English constituency parsing both with large and"
												            " limited training data."
												        ),
												        "labels": ["translation", "machine learning", "vision", "statistics"],
												        "scores": [0.8_17, 0.7_13, 0.0_18, 0.0_18],
												    }		,     )





					@slow
					@require_tf
					def       _lowerCamelCase       (     self: List[Any]   )			-> Any:
												__UpperCAmelCase  :	Tuple   			=      pipeline("zero-shot-classification"		,     model="roberta-large-mnli"		,     framework="tf"   )
												__UpperCAmelCase  :	List[str]   			=      zero_shot_classifier(
												    "Who are you voting for in 2020?"		,     candidate_labels=["politics", "public health", "science"]   )

												self.assertEqual(
												    nested_simplify(__lowerCamelCase   )		,     {
												        "sequence": "Who are you voting for in 2020?",
												        "labels": ["politics", "public health", "science"],
												        "scores": [0.9_76, 0.0_15, 0.0_09],
												    }		,     )
												__UpperCAmelCase  :	Optional[Any]   			=      zero_shot_classifier(
												    "The dominant sequence transduction models are based on complex recurrent or convolutional neural networks"
												    " in an encoder-decoder configuration. The best performing models also connect the encoder and decoder"
												    " through an attention mechanism. We propose a new simple network architecture, the Transformer, based"
												    " solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two"
												    " machine translation tasks show these models to be superior in quality while being more parallelizable"
												    " and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014"
												    " English-to-German translation task, improving over the existing best results, including ensembles by"
												    " over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new"
												    " single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small"
												    " fraction of the training costs of the best models from the literature. We show that the Transformer"
												    " generalizes well to other tasks by applying it successfully to English constituency parsing both with"
												    " large and limited training data."		,     candidate_labels=["machine learning", "statistics", "translation", "vision"]		,     multi_label=__lowerCamelCase		,     )
												self.assertEqual(
												    nested_simplify(__lowerCamelCase   )		,     {
												        "sequence": (
												            "The dominant sequence transduction models are based on complex recurrent or convolutional neural"
												            " networks in an encoder-decoder configuration. The best performing models also connect the"
												            " encoder and decoder through an attention mechanism. We propose a new simple network"
												            " architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence"
												            " and convolutions entirely. Experiments on two machine translation tasks show these models to be"
												            " superior in quality while being more parallelizable and requiring significantly less time to"
												            " train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task,"
												            " improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014"
												            " English-to-French translation task, our model establishes a new single-model state-of-the-art"
												            " BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training"
												            " costs of the best models from the literature. We show that the Transformer generalizes well to"
												            " other tasks by applying it successfully to English constituency parsing both with large and"
												            " limited training data."
												        ),
												        "labels": ["translation", "machine learning", "vision", "statistics"],
												        "scores": [0.8_17, 0.7_13, 0.0_18, 0.0_18],
												    }		,     )












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





	"""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       ,    ):
							"""simple docstring"""







							_UpperCAmelCase									=			parent
							_UpperCAmelCase									=			batch_size
							_UpperCAmelCase									=			image_size
							_UpperCAmelCase									=			num_channels
							_UpperCAmelCase									=			embeddings_size
							_UpperCAmelCase									=			hidden_sizes
							_UpperCAmelCase									=			depths
							_UpperCAmelCase									=			is_training
							_UpperCAmelCase									=			use_labels
							_UpperCAmelCase									=			hidden_act
							_UpperCAmelCase									=			num_labels
							_UpperCAmelCase									=			scope
							_UpperCAmelCase									=			len(UpperCAmelCase    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

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

							_UpperCAmelCase									=			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"""







							_UpperCAmelCase									=			TFResNetModel(config=UpperCAmelCase    )
							_UpperCAmelCase									=			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"""







							_UpperCAmelCase									=			self.num_labels
							_UpperCAmelCase									=			TFResNetForImageClassification(UpperCAmelCase    )
							_UpperCAmelCase									=			model(UpperCAmelCase       ,    labels=UpperCAmelCase    )
							self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.num_labels)    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			self.prepare_config_and_inputs()
							_UpperCAmelCase					, _UpperCAmelCase					, _UpperCAmelCase									=			config_and_inputs
							_UpperCAmelCase									=			{'pixel_values': pixel_values}
							return config, inputs_dict





@require_tf
class __lowerCamelCase (      snake_case__     ,       snake_case__     ,       unittest.TestCase):





	"""simple docstring"""






	UpperCamelCase__								=      (TFResNetModel, TFResNetForImageClassification) if is_tf_available() else ()
	UpperCamelCase__								=      (
	    {"feature-extraction": TFResNetModel, "image-classification": TFResNetForImageClassification}
	    if is_tf_available()
	    else {}
	)

	UpperCamelCase__								=      False
	UpperCamelCase__								=      False
	UpperCamelCase__								=      False
	UpperCamelCase__								=      False
	UpperCamelCase__								=      False

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			TFResNetModelTester(self    )
							_UpperCAmelCase									=			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"""







							_UpperCAmelCase					, _UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs_for_common()

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

													_UpperCAmelCase									=			['pixel_values']
													self.assertListEqual(arg_names[:1]       ,    UpperCAmelCase    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			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    ):
													_UpperCAmelCase									=			model_class(UpperCAmelCase    )
													_UpperCAmelCase									=			model(**self._prepare_for_class(UpperCAmelCase       ,    UpperCAmelCase    )    )

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

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

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

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

																			check_hidden_states_output(UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			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]:
													_UpperCAmelCase									=			TFResNetModel.from_pretrained(UpperCAmelCase    )
													self.assertIsNotNone(UpperCAmelCase    )



def __A    (      )->  Optional[Any]:





						"""simple docstring"""



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





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





	"""simple docstring"""






	@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"""







							_UpperCAmelCase									=			TFResNetForImageClassification.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]    )

							_UpperCAmelCase									=			self.default_image_processor
							_UpperCAmelCase									=			prepare_img()
							_UpperCAmelCase									=			image_processor(images=UpperCAmelCase       ,    return_tensors='tf'    )

							# forward pass
							_UpperCAmelCase									=			model(**UpperCAmelCase    )

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

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

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