






import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import DeformableDetrImageProcessor




class 		UpperCAmelCase_						(	unittest.TestCase					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=7		,				_SCREAMING_SNAKE_CASE=3		,				_SCREAMING_SNAKE_CASE=30		,				_SCREAMING_SNAKE_CASE=400		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE=None		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]		,				_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE=1 / 255		,				_SCREAMING_SNAKE_CASE=True		,				) ->				str:
								# by setting size["longest_edge"] > max_resolution we're effectively not testing this :p
								snake_case_				:							List[Any]						 =       size if size is not None else {"shortest_edge": 18, "longest_edge": 1333}
								snake_case_				:							Dict						 =       parent
								snake_case_				:							Tuple						 =       batch_size
								snake_case_				:							List[str]						 =       num_channels
								snake_case_				:							List[str]						 =       min_resolution
								snake_case_				:							Dict						 =       max_resolution
								snake_case_				:							Any						 =       do_resize
								snake_case_				:							Union[str, Any]						 =       size
								snake_case_				:							Tuple						 =       do_normalize
								snake_case_				:							List[str]						 =       image_mean
								snake_case_				:							Tuple						 =       image_std
								snake_case_				:							Optional[Any]						 =       do_rescale
								snake_case_				:							List[str]						 =       rescale_factor
								snake_case_				:							Optional[int]						 =       do_pad






						def       _lowerCAmelCase       (	self				) ->				Tuple:
								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_normalize": self.do_normalize,
								    "image_mean": self.image_mean,
								    "image_std": self.image_std,
								    "do_rescale": self.do_rescale,
								    "rescale_factor": self.rescale_factor,
								    "do_pad": self.do_pad,
								}






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=False				) ->				Union[str, Any]:
								if not batched:
										snake_case_				:							List[Any]						 =       image_inputs[0]
										if isinstance(_SCREAMING_SNAKE_CASE		,				Image.Image				):
												snake_case_ ,       snake_case_				:							Optional[int]						 =       image.size
										else:
												snake_case_ ,       snake_case_				:							List[str]						 =       image.shape[1], image.shape[2]
										if w < h:
												snake_case_				:							str						 =       int(self.size["shortest_edge"] * h / w				)
												snake_case_				:							Optional[Any]						 =       self.size["shortest_edge"]
										elif w > h:
												snake_case_				:							Optional[int]						 =       self.size["shortest_edge"]
												snake_case_				:							List[Any]						 =       int(self.size["shortest_edge"] * w / h				)
										else:
												snake_case_				:							Any						 =       self.size["shortest_edge"]
												snake_case_				:							Tuple						 =       self.size["shortest_edge"]

								else:
										snake_case_				:							str						 =       []
										for image in image_inputs:
												snake_case_ ,       snake_case_				:							List[Any]						 =       self.get_expected_values([image]				)
												expected_values.append((expected_height, expected_width)				)
										snake_case_				:							Tuple						 =       max(_SCREAMING_SNAKE_CASE		,				key=lambda _SCREAMING_SNAKE_CASE				: item[0]				)[0]
										snake_case_				:							int						 =       max(_SCREAMING_SNAKE_CASE		,				key=lambda _SCREAMING_SNAKE_CASE				: item[1]				)[1]

								return expected_height, expected_width




@require_torch
@require_vision
class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					,  unittest.TestCase					):


						'''simple docstring'''




						A     :   Dict						=					DeformableDetrImageProcessor if is_vision_available() else None






						def       _lowerCAmelCase       (	self				) ->				Optional[int]:
								snake_case_				:							Optional[int]						 =       DeformableDetrImageProcessingTester(self				)






						@property
						def       _lowerCAmelCase       (	self				) ->				Any:
								return self.image_processor_tester.prepare_image_processor_dict()






						def       _lowerCAmelCase       (	self				) ->				Any:
								snake_case_				:							Optional[Any]						 =       self.image_processing_class(**self.image_processor_dict				)
								self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE		,				"image_mean"				)				)
								self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE		,				"image_std"				)				)
								self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE		,				"do_normalize"				)				)
								self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE		,				"do_resize"				)				)
								self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE		,				"do_rescale"				)				)
								self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE		,				"do_pad"				)				)
								self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE		,				"size"				)				)






						def       _lowerCAmelCase       (	self				) ->				int:
								snake_case_				:							Dict						 =       self.image_processing_class.from_dict(self.image_processor_dict				)
								self.assertEqual(image_processor.size		,				{"shortest_edge": 18, "longest_edge": 1333}				)
								self.assertEqual(image_processor.do_pad		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Union[str, Any]						 =       self.image_processing_class.from_dict(
								    self.image_processor_dict		,				size=42		,				max_size=84		,				pad_and_return_pixel_mask=_SCREAMING_SNAKE_CASE				)
								self.assertEqual(image_processor.size		,				{"shortest_edge": 42, "longest_edge": 84}				)
								self.assertEqual(image_processor.do_pad		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								pass






						def       _lowerCAmelCase       (	self				) ->				Dict:
								# Initialize image_processing
								snake_case_				:							List[str]						 =       self.image_processing_class(**self.image_processor_dict				)
								# create random PIL images
								snake_case_				:							str						 =       prepare_image_inputs(self.image_processor_tester		,				equal_resolution=_SCREAMING_SNAKE_CASE				)
								for image in image_inputs:
										self.assertIsInstance(_SCREAMING_SNAKE_CASE		,				Image.Image				)

								# Test not batched input
								snake_case_				:							Any						 =       image_processing(image_inputs[0]		,				return_tensors="pt"				).pixel_values

								snake_case_ ,       snake_case_				:							Optional[int]						 =       self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE				)

								self.assertEqual(
								    encoded_images.shape		,				(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,				)

								# Test batched
								snake_case_ ,       snake_case_				:							List[str]						 =       self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE		,				batched=_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Tuple						 =       image_processing(_SCREAMING_SNAKE_CASE		,				return_tensors="pt"				).pixel_values
								self.assertEqual(
								    encoded_images.shape		,				(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        expected_height,
								        expected_width,
								    )		,				)






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								# Initialize image_processing
								snake_case_				:							Dict						 =       self.image_processing_class(**self.image_processor_dict				)
								# create random numpy tensors
								snake_case_				:							Optional[Any]						 =       prepare_image_inputs(self.image_processor_tester		,				equal_resolution=_SCREAMING_SNAKE_CASE		,				numpify=_SCREAMING_SNAKE_CASE				)
								for image in image_inputs:
										self.assertIsInstance(_SCREAMING_SNAKE_CASE		,				np.ndarray				)

								# Test not batched input
								snake_case_				:							Optional[Any]						 =       image_processing(image_inputs[0]		,				return_tensors="pt"				).pixel_values

								snake_case_ ,       snake_case_				:							Tuple						 =       self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE				)

								self.assertEqual(
								    encoded_images.shape		,				(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,				)

								# Test batched
								snake_case_				:							Dict						 =       image_processing(_SCREAMING_SNAKE_CASE		,				return_tensors="pt"				).pixel_values

								snake_case_ ,       snake_case_				:							Any						 =       self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE		,				batched=_SCREAMING_SNAKE_CASE				)

								self.assertEqual(
								    encoded_images.shape		,				(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        expected_height,
								        expected_width,
								    )		,				)






						def       _lowerCAmelCase       (	self				) ->				List[str]:
								# Initialize image_processing
								snake_case_				:							Optional[Any]						 =       self.image_processing_class(**self.image_processor_dict				)
								# create random PyTorch tensors
								snake_case_				:							Optional[Any]						 =       prepare_image_inputs(self.image_processor_tester		,				equal_resolution=_SCREAMING_SNAKE_CASE		,				torchify=_SCREAMING_SNAKE_CASE				)
								for image in image_inputs:
										self.assertIsInstance(_SCREAMING_SNAKE_CASE		,				torch.Tensor				)

								# Test not batched input
								snake_case_				:							Optional[Any]						 =       image_processing(image_inputs[0]		,				return_tensors="pt"				).pixel_values

								snake_case_ ,       snake_case_				:							Any						 =       self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE				)

								self.assertEqual(
								    encoded_images.shape		,				(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,				)

								# Test batched
								snake_case_				:							Dict						 =       image_processing(_SCREAMING_SNAKE_CASE		,				return_tensors="pt"				).pixel_values

								snake_case_ ,       snake_case_				:							Dict						 =       self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE		,				batched=_SCREAMING_SNAKE_CASE				)

								self.assertEqual(
								    encoded_images.shape		,				(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        expected_height,
								        expected_width,
								    )		,				)






						@slow
						def       _lowerCAmelCase       (	self				) ->				Optional[int]:
								# prepare image and target
								snake_case_				:							Any						 =       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
								with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt"		,				"r"				) as f:
										snake_case_				:							Optional[Any]						 =       json.loads(f.read()				)

								snake_case_				:							str						 =       {"image_id": 3_9769, "annotations": target}

								# encode them
								snake_case_				:							int						 =       DeformableDetrImageProcessor()
								snake_case_				:							Optional[Any]						 =       image_processing(images=_SCREAMING_SNAKE_CASE		,				annotations=_SCREAMING_SNAKE_CASE		,				return_tensors="pt"				)

								# verify pixel values
								snake_case_				:							Dict						 =       torch.Size([1, 3, 800, 1066]				)
								self.assertEqual(encoding["pixel_values"].shape		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Any						 =       torch.tensor([0.2796, 0.3138, 0.3481]				)
								self.assertTrue(torch.allclose(encoding["pixel_values"][0, 0, 0, :3]		,				_SCREAMING_SNAKE_CASE		,				atol=1e-4				)				)

								# verify area
								snake_case_				:							List[str]						 =       torch.tensor([5887.9600, 1_1250.2061, 48_9353.8438, 83_7122.7500, 14_7967.5156, 16_5732.3438]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["area"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify boxes
								snake_case_				:							List[Any]						 =       torch.Size([6, 4]				)
								self.assertEqual(encoding["labels"][0]["boxes"].shape		,				_SCREAMING_SNAKE_CASE				)
								snake_case_				:							Tuple						 =       torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["boxes"][0]		,				_SCREAMING_SNAKE_CASE		,				atol=1e-3				)				)
								# verify image_id
								snake_case_				:							int						 =       torch.tensor([3_9769]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["image_id"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify is_crowd
								snake_case_				:							List[str]						 =       torch.tensor([0, 0, 0, 0, 0, 0]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["iscrowd"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify class_labels
								snake_case_				:							List[Any]						 =       torch.tensor([75, 75, 63, 65, 17, 17]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["class_labels"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify orig_size
								snake_case_				:							Union[str, Any]						 =       torch.tensor([480, 640]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["orig_size"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify size
								snake_case_				:							Optional[Any]						 =       torch.tensor([800, 1066]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["size"]		,				_SCREAMING_SNAKE_CASE				)				)






						@slow
						def       _lowerCAmelCase       (	self				) ->				Any:
								# prepare image, target and masks_path
								snake_case_				:							Dict						 =       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
								with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt"		,				"r"				) as f:
										snake_case_				:							Tuple						 =       json.loads(f.read()				)

								snake_case_				:							int						 =       {"file_name": "000000039769.png", "image_id": 3_9769, "segments_info": target}

								snake_case_				:							int						 =       pathlib.Path("./tests/fixtures/tests_samples/COCO/coco_panoptic"				)

								# encode them
								snake_case_				:							Tuple						 =       DeformableDetrImageProcessor(format="coco_panoptic"				)
								snake_case_				:							Optional[Any]						 =       image_processing(images=_SCREAMING_SNAKE_CASE		,				annotations=_SCREAMING_SNAKE_CASE		,				masks_path=_SCREAMING_SNAKE_CASE		,				return_tensors="pt"				)

								# verify pixel values
								snake_case_				:							str						 =       torch.Size([1, 3, 800, 1066]				)
								self.assertEqual(encoding["pixel_values"].shape		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       torch.tensor([0.2796, 0.3138, 0.3481]				)
								self.assertTrue(torch.allclose(encoding["pixel_values"][0, 0, 0, :3]		,				_SCREAMING_SNAKE_CASE		,				atol=1e-4				)				)

								# verify area
								snake_case_				:							Optional[int]						 =       torch.tensor([14_7979.6875, 16_5527.0469, 48_4638.5938, 1_1292.9375, 5879.6562, 7634.1147]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["area"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify boxes
								snake_case_				:							Optional[int]						 =       torch.Size([6, 4]				)
								self.assertEqual(encoding["labels"][0]["boxes"].shape		,				_SCREAMING_SNAKE_CASE				)
								snake_case_				:							int						 =       torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["boxes"][0]		,				_SCREAMING_SNAKE_CASE		,				atol=1e-3				)				)
								# verify image_id
								snake_case_				:							List[Any]						 =       torch.tensor([3_9769]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["image_id"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify is_crowd
								snake_case_				:							Any						 =       torch.tensor([0, 0, 0, 0, 0, 0]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["iscrowd"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify class_labels
								snake_case_				:							Optional[Any]						 =       torch.tensor([17, 17, 63, 75, 75, 93]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["class_labels"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify masks
								snake_case_				:							Optional[Any]						 =       82_2873
								self.assertEqual(encoding["labels"][0]["masks"].sum().item()		,				_SCREAMING_SNAKE_CASE				)
								# verify orig_size
								snake_case_				:							int						 =       torch.tensor([480, 640]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["orig_size"]		,				_SCREAMING_SNAKE_CASE				)				)
								# verify size
								snake_case_				:							Dict						 =       torch.tensor([800, 1066]				)
								self.assertTrue(torch.allclose(encoding["labels"][0]["size"]		,				_SCREAMING_SNAKE_CASE				)				)








from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import RegNetConfig
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 TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST, TFRegNetForImageClassification, TFRegNetModel


if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor




class 		UpperCAmelCase_						:


						'''simple docstring'''




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






						def       _lowerCAmelCase       (	self				) ->				Dict:
								snake_case_				:							Union[str, Any]						 =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

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

								snake_case_				:							Optional[int]						 =       self.get_config()
								return config, pixel_values, labels






						def       _lowerCAmelCase       (	self				) ->				Optional[int]:
								return RegNetConfig(
								    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		,				)






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Union[str, Any]:
								snake_case_				:							Union[str, Any]						 =       TFRegNetModel(config=_SCREAMING_SNAKE_CASE				)
								snake_case_				:							List[str]						 =       model(_SCREAMING_SNAKE_CASE		,				training=_SCREAMING_SNAKE_CASE				)
								# 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       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Tuple:
								snake_case_				:							Optional[int]						 =       self.num_labels
								snake_case_				:							Tuple						 =       TFRegNetForImageClassification(_SCREAMING_SNAKE_CASE				)
								snake_case_				:							List[str]						 =       model(_SCREAMING_SNAKE_CASE		,				labels=_SCREAMING_SNAKE_CASE		,				training=_SCREAMING_SNAKE_CASE				)
								self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.num_labels)				)






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								snake_case_				:							Optional[Any]						 =       self.prepare_config_and_inputs()
								snake_case_ ,       snake_case_ ,       snake_case_				:							Union[str, Any]						 =       config_and_inputs
								snake_case_				:							Any						 =       {"pixel_values": pixel_values}
								return config, inputs_dict




@require_tf
class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					,  SCREAMING_SNAKE_CASE__					,  unittest.TestCase					):


						'''simple docstring'''




						A     :   Optional[int]						=					(TFRegNetModel, TFRegNetForImageClassification) if is_tf_available() else ()
						A     :   Dict						=					(
						    {'feature-extraction': TFRegNetModel, 'image-classification': TFRegNetForImageClassification}
						    if is_tf_available()
						    else {}
						)

						A     :   List[Any]						=					False
						A     :   List[str]						=					False
						A     :   Optional[Any]						=					False
						A     :   List[Any]						=					False
						A     :   List[Any]						=					False






						def       _lowerCAmelCase       (	self				) ->				Any:
								snake_case_				:							List[Any]						 =       TFRegNetModelTester(self				)
								snake_case_				:							Any						 =       ConfigTester(self		,				config_class=_SCREAMING_SNAKE_CASE		,				has_text_modality=_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Dict:
								return






						@unittest.skip(reason="RegNet does not use inputs_embeds"				)
						def       _lowerCAmelCase       (	self				) ->				Dict:
								pass






						@unittest.skipIf(
						    not is_tf_available() or len(tf.config.list_physical_devices("GPU"				)				) == 0		,				reason="TF does not support backprop for grouped convolutions on CPU."		,				)
						@slow
						def       _lowerCAmelCase       (	self				) ->				Any:
								super().test_keras_fit()






						@unittest.skip(reason="RegNet does not support input and output embeddings"				)
						def       _lowerCAmelCase       (	self				) ->				str:
								pass






						def       _lowerCAmelCase       (	self				) ->				int:
								snake_case_ ,       snake_case_				:							List[Any]						 =       self.model_tester.prepare_config_and_inputs_for_common()

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

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






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								snake_case_				:							List[Any]						 =       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Tuple:
								def check_hidden_states_output(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
										snake_case_				:							List[str]						 =       model_class(_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Tuple						 =       model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)		,				training=_SCREAMING_SNAKE_CASE				)

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

										snake_case_				:							Any						 =       self.model_tester.num_stages
										self.assertEqual(len(_SCREAMING_SNAKE_CASE				)		,				expected_num_stages + 1				)

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

								snake_case_ ,       snake_case_				:							Dict						 =       self.model_tester.prepare_config_and_inputs_for_common()
								snake_case_				:							Optional[int]						 =       ["basic", "bottleneck"]
								for model_class in self.all_model_classes:
										for layer_type in layers_type:
												snake_case_				:							Any						 =       layer_type
												snake_case_				:							int						 =       True
												check_hidden_states_output(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

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

												check_hidden_states_output(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Optional[Any]:
								snake_case_ ,       snake_case_				:							List[Any]						 =       self.model_tester.prepare_config_and_inputs_for_common()

								def check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE={}				):
										snake_case_				:							List[Any]						 =       model(_SCREAMING_SNAKE_CASE		,				return_dict=_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				)
										snake_case_				:							List[Any]						 =       model(_SCREAMING_SNAKE_CASE		,				return_dict=_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				).to_tuple()

										def recursive_check(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
												if isinstance(_SCREAMING_SNAKE_CASE		,				(List, Tuple)				):
														for tuple_iterable_value, dict_iterable_value in zip(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
																recursive_check(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
												elif tuple_object is None:
														return
												else:
														self.assertTrue(
														    all(tf.equal(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)				)		,				msg=(
														        "Tuple and dict output are not equal. Difference:"
														        f''' {tf.math.reduce_max(tf.abs(tuple_object - dict_object				)				)}'''
														    )		,				)

												recursive_check(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								for model_class in self.all_model_classes:
										snake_case_				:							str						 =       model_class(_SCREAMING_SNAKE_CASE				)

										snake_case_				:							List[Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Optional[Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

										snake_case_				:							Union[str, Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				return_labels=_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Union[str, Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				return_labels=_SCREAMING_SNAKE_CASE				)
										check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

										snake_case_				:							Optional[Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Union[str, Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				{"output_hidden_states": True}				)

										snake_case_				:							List[Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				return_labels=_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Dict						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				return_labels=_SCREAMING_SNAKE_CASE				)
										check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				{"output_hidden_states": True}				)






						def       _lowerCAmelCase       (	self				) ->				List[str]:
								snake_case_				:							List[str]						 =       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE				)






						@slow
						def       _lowerCAmelCase       (	self				) ->				Any:
								for model_name in TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										snake_case_				:							Dict						 =       TFRegNetModel.from_pretrained(_SCREAMING_SNAKE_CASE				)
										self.assertIsNotNone(_SCREAMING_SNAKE_CASE				)




def      lowerCAmelCase__	(    ):
		snake_case_				:							int						 =       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"    )
		return image




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


						'''simple docstring'''




						@cached_property
						def       _lowerCAmelCase       (	self				) ->				List[Any]:
								return (
								    AutoImageProcessor.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]				)
								    if is_vision_available()
								    else None
								)






						@slow
						def       _lowerCAmelCase       (	self				) ->				Dict:
								snake_case_				:							str						 =       TFRegNetForImageClassification.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]				)

								snake_case_				:							int						 =       self.default_image_processor
								snake_case_				:							List[Any]						 =       prepare_img()
								snake_case_				:							str						 =       image_processor(images=_SCREAMING_SNAKE_CASE		,				return_tensors="tf"				)

								# forward pass
								snake_case_				:							Any						 =       model(**_SCREAMING_SNAKE_CASE		,				training=_SCREAMING_SNAKE_CASE				)

								# verify the logits
								snake_case_				:							List[str]						 =       tf.TensorShape((1, 1000)				)
								self.assertEqual(outputs.logits.shape		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Optional[int]						 =       tf.constant([-0.4180, -1.5051, -3.4836]				)

								tf.debugging.assert_near(outputs.logits[0, :3]		,				_SCREAMING_SNAKE_CASE		,				atol=1e-4				)
