

from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

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

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
			from transformers import (
			    TFBertModel,
			    TFCLIPVisionModel,
			    TFDeiTModel,
			    TFRobertaModel,
			    TFVisionTextDualEncoderModel,
			    TFViTModel,
			    VisionTextDualEncoderConfig,
			)

if is_vision_available():
			from PIL import Image

			from transformers import VisionTextDualEncoderProcessor

def        lowerCamelCase__       (    _a):
	if isinstance(_a							,	collections.abc.Iterable):
		return x
	return (x, x)






@require_tf
class _UpperCamelCase							:
			'''simple docstring'''







			def 							__UpperCamelCase       (	self							:       Optional[int]					,					a							:       List[str]					,					a							:       int		)							->				Union[str, Any]:

				"""simple docstring"""

				pass
			def 							__UpperCamelCase       (	self							:       Tuple		)							->				Optional[Any]:

				"""simple docstring"""

				pass
			def 							__UpperCamelCase       (	self							:       Any		)							->				List[Any]:

				"""simple docstring"""

				pass
			def 							__UpperCamelCase       (	self							:       Optional[int]					,					a							:       Any					,					a							:       int					,					a							:       Optional[int]					,					a							:       List[str]					,					a							:       Optional[Any]=None					,					**a							:       List[Any]		)							->				int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[Any]    =				VisionTextDualEncoderConfig.from_vision_text_configs(a					,					a		)

				SCREAMING_SNAKE_CASE      :					Dict    =				TFVisionTextDualEncoderModel(a		)

				SCREAMING_SNAKE_CASE      :					Any    =				model(input_ids=a					,					pixel_values=a					,					attention_mask=a		)

				self.assertEqual(output["text_embeds"].shape					,					(input_ids.shape[0], config.projection_dim)		)
				self.assertEqual(output["image_embeds"].shape					,					(pixel_values.shape[0], config.projection_dim)		)
			def 							__UpperCamelCase       (	self							:       Union[str, Any]					,					a							:       Optional[int]					,					a							:       Dict					,					a							:       List[str]					,					a							:       Tuple					,					a							:       Union[str, Any]=None					,					**a							:       int		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					Tuple    =				self.get_vision_text_model(a					,					a		)
				SCREAMING_SNAKE_CASE      :					Tuple    =				TFVisionTextDualEncoderModel(vision_model=a					,					text_model=a		)

				SCREAMING_SNAKE_CASE      :					List[str]    =				model(input_ids=a					,					pixel_values=a					,					attention_mask=a		)

				self.assertEqual(output["text_embeds"].shape					,					(input_ids.shape[0], model.config.projection_dim)		)
				self.assertEqual(output["image_embeds"].shape					,					(pixel_values.shape[0], model.config.projection_dim)		)
			def 							__UpperCamelCase       (	self							:       str					,					a							:       int					,					a							:       List[str]					,					a							:       Optional[Any]					,					a							:       Optional[Any]					,					a							:       List[Any]=None					,					**a							:       Dict		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					Tuple    =				self.get_vision_text_model(a					,					a		)
				SCREAMING_SNAKE_CASE      :					List[str]    =				{"vision_model": vision_model, "text_model": text_model}
				SCREAMING_SNAKE_CASE      :					Optional[int]    =				TFVisionTextDualEncoderModel.from_vision_text_pretrained(**a		)

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				model(input_ids=a					,					pixel_values=a					,					attention_mask=a		)

				self.assertEqual(output["text_embeds"].shape					,					(input_ids.shape[0], model.config.projection_dim)		)
				self.assertEqual(output["image_embeds"].shape					,					(pixel_values.shape[0], model.config.projection_dim)		)
			def 							__UpperCamelCase       (	self							:       int					,					a							:       Dict					,					a							:       Tuple					,					a							:       List[str]					,					a							:       int					,					a							:       Tuple=None					,					**a							:       List[Any]		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					Tuple    =				self.get_vision_text_model(a					,					a		)
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				TFVisionTextDualEncoderModel(vision_model=a					,					text_model=a		)

				SCREAMING_SNAKE_CASE      :					Any    =				model(input_ids=a					,					pixel_values=a					,					attention_mask=a		)
				SCREAMING_SNAKE_CASE      :					str    =				output[0].numpy()

				with tempfile.TemporaryDirectory() as tmpdirname:
					model.save_pretrained(a		)
					SCREAMING_SNAKE_CASE      :					Optional[Any]    =				TFVisionTextDualEncoderModel.from_pretrained(a		)

					SCREAMING_SNAKE_CASE      :					List[str]    =				model(input_ids=a					,					pixel_values=a					,					attention_mask=a		)
					SCREAMING_SNAKE_CASE      :					Any    =				after_output[0].numpy()
					SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				np.amax(np.abs(out_a - out_a		)		)
					self.assertLessEqual(a					,					1e-5		)
			def 							__UpperCamelCase       (	self							:       int					,					a							:       List[str]					,					a							:       Union[str, Any]					,					a							:       Optional[int]					,					a							:       str					,					a							:       Optional[Any]=None					,					**a							:       Optional[Any]		)							->				int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					Any    =				self.get_vision_text_model(a					,					a		)
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				TFVisionTextDualEncoderModel(vision_model=a					,					text_model=a		)

				SCREAMING_SNAKE_CASE      :					int    =				model(
				    input_ids=a					,					pixel_values=a					,					attention_mask=a					,					output_attentions=a		)

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				output.vision_model_output.attentions
				self.assertEqual(len(a		)					,					vision_config.num_hidden_layers		)

				# in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
				SCREAMING_SNAKE_CASE      :					str    =				to_atuple(vision_model.config.image_size		)
				SCREAMING_SNAKE_CASE      :					Dict    =				to_atuple(vision_model.config.patch_size		)
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
				SCREAMING_SNAKE_CASE      :					Dict    =				num_patches + 1
				self.assertEqual(vision_attentions[0].shape[-3:]					,					(vision_config.num_attention_heads, seq_len, seq_len)		)

				SCREAMING_SNAKE_CASE      :					Any    =				output.text_model_output.attentions
				self.assertEqual(len(a		)					,					text_config.num_hidden_layers		)

				self.assertEqual(
				    text_attentions[0].shape[-3:]					,					(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])					,					)
			def 							__UpperCamelCase       (	self							:       str					,					a							:       np.ndarray					,					a							:       np.ndarray					,					a							:       float		)							->				Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Tuple    =				np.abs((a - b)		).max()
				self.assertLessEqual(a					,					a					,					F"Difference between torch and flax is {diff} (>= {tol})."		)
			def 							__UpperCamelCase       (	self							:       Dict		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				self.prepare_config_and_inputs()
				self.check_vision_text_dual_encoder_model(**a		)
			def 							__UpperCamelCase       (	self							:       Union[str, Any]		)							->				Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				self.prepare_config_and_inputs()
				self.check_model_from_pretrained_configs(**a		)
			def 							__UpperCamelCase       (	self							:       int		)							->				Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Any    =				self.prepare_config_and_inputs()
				self.check_vision_text_dual_encoder_from_pretrained(**a		)
			def 							__UpperCamelCase       (	self							:       int		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Dict    =				self.prepare_config_and_inputs()
				self.check_save_load(**a		)
			def 							__UpperCamelCase       (	self							:       Optional[Any]		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				self.prepare_config_and_inputs()
				self.check_vision_text_output_attention(**a		)






			@slow
			def 							__UpperCamelCase       (	self							:       List[Any]		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					List[str]    =				self.get_pretrained_model_and_inputs()

				SCREAMING_SNAKE_CASE      :					str    =				model_a(**a		)
				SCREAMING_SNAKE_CASE      :					List[str]    =				outputs[0].numpy()

				with tempfile.TemporaryDirectory() as tmp_dirname:
					model_a.save_pretrained(a		)
					SCREAMING_SNAKE_CASE      :					Optional[int]    =				TFVisionTextDualEncoderModel.from_pretrained(a		)

					SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				model_a(**a		)
					SCREAMING_SNAKE_CASE      :					str    =				after_outputs[0].numpy()
					SCREAMING_SNAKE_CASE      :					Optional[int]    =				np.amax(np.abs(out_a - out_a		)		)
					self.assertLessEqual(a					,					1e-5		)






@require_tf
class _UpperCamelCase							(							__A							,		unittest.TestCase      ):
			'''simple docstring'''







			def 							__UpperCamelCase       (	self							:       List[str]		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				TFVisionTextDualEncoderModel.from_vision_text_pretrained(
				    "hf-internal-testing/tiny-random-vit"					,					"hf-internal-testing/tiny-random-bert"		)
				SCREAMING_SNAKE_CASE      :					Any    =				13
				SCREAMING_SNAKE_CASE      :					str    =				floats_tensor(
				    [
				        batch_size,
				        model.vision_model.config.num_channels,
				        model.vision_model.config.image_size,
				        model.vision_model.config.image_size,
				    ]		)
				SCREAMING_SNAKE_CASE      :					int    =				ids_tensor([batch_size, 4]					,					model.text_model.config.vocab_size		)
				SCREAMING_SNAKE_CASE      :					List[str]    =				random_attention_mask([batch_size, 4]		)
				SCREAMING_SNAKE_CASE      :					Tuple    =				{"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

				return model, inputs
			def 							__UpperCamelCase       (	self							:       Optional[int]					,					a							:       List[Any]					,					a							:       Dict		)							->				Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Tuple    =				TFViTModel(a					,					name="vision_model"		)
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				TFBertModel(a					,					name="text_model"		)
				return vision_model, text_model






			def 							__UpperCamelCase       (	self							:       Union[str, Any]		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[str]    =				TFViTModelTester(self		)
				SCREAMING_SNAKE_CASE      :					Tuple    =				TFBertModelTester(self		)
				SCREAMING_SNAKE_CASE      :					int    =				vit_model_tester.prepare_config_and_inputs()
				SCREAMING_SNAKE_CASE      :					Optional[int]    =				bert_model_tester.prepare_config_and_inputs()

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					Any    =				vision_config_and_inputs

				(
				    (
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,
				)      :					Tuple    =				text_config_and_inputs

				return {
				    "text_config": text_config,
				    "vision_config": vision_config,
				    "pixel_values": pixel_values,
				    "attention_mask": input_mask,
				    "input_ids": input_ids,
				    "text_token_type_ids": token_type_ids,
				    "text_sequence_labels": sequence_labels,
				    "text_token_labels": token_labels,
				    "text_choice_labels": choice_labels,
				}






@require_tf
class _UpperCamelCase							(							__A							,		unittest.TestCase      ):
			'''simple docstring'''







			def 							__UpperCamelCase       (	self							:       Dict		)							->				Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Dict    =				TFVisionTextDualEncoderModel.from_vision_text_pretrained(
				    "Rocketknight1/tiny-random-deit-tf"					,					"hf-internal-testing/tiny-random-roberta"		)
				SCREAMING_SNAKE_CASE      :					Any    =				13
				SCREAMING_SNAKE_CASE      :					Tuple    =				floats_tensor(
				    [
				        batch_size,
				        model.vision_model.config.num_channels,
				        model.vision_model.config.image_size,
				        model.vision_model.config.image_size,
				    ]		)
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				ids_tensor([batch_size, 4]					,					model.text_model.config.vocab_size		)
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				random_attention_mask([batch_size, 4]		)
				SCREAMING_SNAKE_CASE      :					Dict    =				{"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

				return model, inputs
			def 							__UpperCamelCase       (	self							:       Dict					,					a							:       Tuple					,					a							:       Any					,					a							:       Union[str, Any]					,					a							:       Tuple					,					a							:       Optional[Any]=None					,					**a							:       Optional[int]		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					str    =				self.get_vision_text_model(a					,					a		)
				SCREAMING_SNAKE_CASE      :					str    =				TFVisionTextDualEncoderModel(vision_model=a					,					text_model=a		)

				SCREAMING_SNAKE_CASE      :					Tuple    =				model(
				    input_ids=a					,					pixel_values=a					,					attention_mask=a					,					output_attentions=a		)

				SCREAMING_SNAKE_CASE      :					Tuple    =				output.vision_model_output.attentions
				self.assertEqual(len(a		)					,					vision_config.num_hidden_layers		)

				# in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
				SCREAMING_SNAKE_CASE      :					int    =				to_atuple(vision_model.config.image_size		)
				SCREAMING_SNAKE_CASE      :					Dict    =				to_atuple(vision_model.config.patch_size		)
				SCREAMING_SNAKE_CASE      :					List[Any]    =				(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
				SCREAMING_SNAKE_CASE      :					int    =				num_patches + 2
				self.assertEqual(vision_attentions[0].shape[-3:]					,					(vision_config.num_attention_heads, seq_len, seq_len)		)

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				output.text_model_output.attentions
				self.assertEqual(len(a		)					,					text_config.num_hidden_layers		)

				self.assertEqual(
				    text_attentions[0].shape[-3:]					,					(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])					,					)
			def 							__UpperCamelCase       (	self							:       str					,					a							:       Optional[Any]					,					a							:       Optional[Any]		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				TFDeiTModel(a					,					name="vision_model"		)
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				TFRobertaModel(a					,					name="text_model"		)
				return vision_model, text_model






			def 							__UpperCamelCase       (	self							:       int		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Tuple    =				TFDeiTModelTester(self		)
				SCREAMING_SNAKE_CASE      :					List[str]    =				TFRobertaModelTester(self		)
				SCREAMING_SNAKE_CASE      :					List[str]    =				vit_model_tester.prepare_config_and_inputs()
				SCREAMING_SNAKE_CASE      :					Any    =				bert_model_tester.prepare_config_and_inputs()

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					Tuple    =				vision_config_and_inputs

				(
				    (
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,
				)      :					Any    =				text_config_and_inputs

				return {
				    "text_config": text_config,
				    "vision_config": vision_config,
				    "pixel_values": pixel_values,
				    "attention_mask": input_mask,
				    "input_ids": input_ids,
				    "text_token_type_ids": token_type_ids,
				    "text_sequence_labels": sequence_labels,
				    "text_token_labels": token_labels,
				    "text_choice_labels": choice_labels,
				}






@require_tf
class _UpperCamelCase							(							__A							,		unittest.TestCase      ):
			'''simple docstring'''







			def 							__UpperCamelCase       (	self							:       Union[str, Any]		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					str    =				TFVisionTextDualEncoderModel.from_vision_text_pretrained(
				    "Rocketknight1/tiny-random-clip-tf"					,					"hf-internal-testing/tiny-random-bert"		)
				SCREAMING_SNAKE_CASE      :					Optional[int]    =				13
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				floats_tensor(
				    [
				        batch_size,
				        model.vision_model.config.num_channels,
				        model.vision_model.config.image_size,
				        model.vision_model.config.image_size,
				    ]		)
				SCREAMING_SNAKE_CASE      :					Dict    =				ids_tensor([batch_size, 4]					,					model.text_model.config.vocab_size		)
				SCREAMING_SNAKE_CASE      :					Dict    =				random_attention_mask([batch_size, 4]		)
				SCREAMING_SNAKE_CASE      :					Tuple    =				{"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

				return model, inputs
			def 							__UpperCamelCase       (	self							:       Union[str, Any]					,					a							:       Optional[int]					,					a							:       int		)							->				Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Any    =				TFCLIPVisionModel(a					,					name="vision_model"		)
				SCREAMING_SNAKE_CASE      :					List[Any]    =				TFBertModel(a					,					name="text_model"		)
				return vision_model, text_model






			def 							__UpperCamelCase       (	self							:       Union[str, Any]		)							->				Optional[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				TFCLIPVisionModelTester(self		)
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				TFBertModelTester(self		)
				SCREAMING_SNAKE_CASE      :					Tuple    =				clip_model_tester.prepare_config_and_inputs()
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				bert_model_tester.prepare_config_and_inputs()

				SCREAMING_SNAKE_CASE   ,SCREAMING_SNAKE_CASE      :					int    =				vision_config_and_inputs

				(
				    (
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,
				)      :					Union[str, Any]    =				text_config_and_inputs

				return {
				    "text_config": text_config,
				    "vision_config": vision_config,
				    "pixel_values": pixel_values,
				    "attention_mask": input_mask,
				    "input_ids": input_ids,
				    "text_token_type_ids": token_type_ids,
				    "text_sequence_labels": sequence_labels,
				    "text_token_labels": token_labels,
				    "text_choice_labels": choice_labels,
				}






@require_vision
@require_tf
class _UpperCamelCase							(							unittest.TestCase      ):
			'''simple docstring'''







			@slow
			def 							__UpperCamelCase       (	self							:       List[str]		)							->				int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				TFVisionTextDualEncoderModel.from_pretrained(
				    "clip-italian/clip-italian"					,					logit_scale_init_value=1.0					,					from_pt=a		)
				SCREAMING_SNAKE_CASE      :					Any    =				VisionTextDualEncoderProcessor.from_pretrained("clip-italian/clip-italian"		)

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
				SCREAMING_SNAKE_CASE      :					List[Any]    =				processor(
				    text=["una foto di un gatto", "una foto di un cane"]					,					images=a					,					padding=a					,					return_tensors="np"		)

				SCREAMING_SNAKE_CASE      :					Tuple    =				model(**a		)

				# verify the logits
				self.assertEqual(outputs.logits_per_image.shape					,					(inputs.pixel_values.shape[0], inputs.input_ids.shape[0])		)
				self.assertEqual(
				    outputs.logits_per_text.shape					,					(inputs.input_ids.shape[0], inputs.pixel_values.shape[0])					,					)

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				np.array([[1.228_4727, 0.310_4122]]		)

				self.assertTrue(np.allclose(outputs.logits_per_image.numpy()					,					a					,					atol=1e-3		)		)


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowercase_       		=  logging.get_logger(__name__)

lowercase_       		=  {
    "microsoft/resnet-50": "https://huggingface.co/microsoft/resnet-50/blob/main/config.json",
}


class  A						(							_UpperCAmelCase    ,							_UpperCAmelCase ):







    """simple docstring"""





    lowerCamelCase			=							'resnet'
    lowerCamelCase			=							['basic', 'bottleneck']


    def __init__(      self :       Optional[Any],lowercase_ :       int=3,lowercase_ :       List[str]=6_4,lowercase_ :       int=[2_5_6, 5_1_2, 1_0_2_4, 2_0_4_8],lowercase_ :       Tuple=[3, 4, 6, 3],lowercase_ :       Union[str, Any]="bottleneck",lowercase_ :       List[str]="relu",lowercase_ :       Tuple=False,lowercase_ :       List[str]=None,lowercase_ :       List[Any]=None,**lowercase_ :       str,)->    Optional[Any]:





        '''simple docstring'''







        super().__init__(**lowercase_		)
        if layer_type not in self.layer_types:
            raise ValueError(F'layer_type={layer_type} is not one of {",".join(self.layer_types		)}'		)
        A__          =   num_channels
        A__          =   embedding_size
        A__          =   hidden_sizes
        A__          =   depths
        A__          =   layer_type
        A__          =   hidden_act
        A__          =   downsample_in_first_stage
        A__          =   ['stem'] + [F'stage{idx}' for idx in range(1,len(lowercase_		) + 1		)]
        A__      ,						A__          =   get_aligned_output_features_output_indices(
            out_features=lowercase_,out_indices=lowercase_,stage_names=self.stage_names		)




class  A						(							_UpperCAmelCase ):







    """simple docstring"""





    lowerCamelCase			=							version.parse('1.11' )


    @property
    def 						snake_case__     (      self :       List[Any]		)->    Mapping[str, Mapping[int, str]]:





        '''simple docstring'''







        return OrderedDict(
            [
                ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
            ]		)


    @property
    def 						snake_case__     (      self :       Any		)->    float:





        '''simple docstring'''







        return 1E-3

