





"""simple docstring"""





import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_vision
from transformers.utils import is_vision_available


if is_vision_available():
							from PIL import Image

							from transformers import (
							    AutoProcessor,
							    BertTokenizerFast,
							    BlipImageProcessor,
							    GPTaTokenizer,
							    InstructBlipProcessor,
							    PreTrainedTokenizerFast,
							)
@require_vision
class 		SCREAMING_SNAKE_CASE_							(    unittest.TestCase   ):
				"""simple docstring"""




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      Union[str, Any]         =tempfile.mkdtemp()

											__lowerCamelCase      :      List[str]         =BlipImageProcessor()
											__lowerCamelCase      :      int         =GPTaTokenizer.from_pretrained('''hf-internal-testing/tiny-random-GPT2Model'''			)
											__lowerCamelCase      :      Any         =BertTokenizerFast.from_pretrained('''hf-internal-testing/tiny-random-bert'''			)

											__lowerCamelCase      :      Union[str, Any]         =InstructBlipProcessor(__lowercase						,    __lowercase						,    __lowercase			)

											processor.save_pretrained(self.tmpdirname			)




				def 					__lowercase  (     self  :Tuple						,    **__lowercase  :Dict			):
											return AutoProcessor.from_pretrained(self.tmpdirname						,    **__lowercase			).tokenizer




				def 					__lowercase  (     self  :Dict						,    **__lowercase  :int			):
											return AutoProcessor.from_pretrained(self.tmpdirname						,    **__lowercase			).image_processor




				def 					__lowercase  (     self  :int						,    **__lowercase  :Any			):
											return AutoProcessor.from_pretrained(self.tmpdirname						,    **__lowercase			).qformer_tokenizer




				def 					__lowercase  (     self  :Tuple			):
											shutil.rmtree(self.tmpdirname			)




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      List[str]         =[np.random.randint(255						,    size=(3, 30, 400)						,    dtype=np.uinta			)]

											__lowerCamelCase      :      Optional[Any]         =[Image.fromarray(np.moveaxis(__lowercase						,    0						,    -1			)			) for x in image_inputs]

											return image_inputs




				def 					__lowercase  (     self  :List[Any]			):
											__lowerCamelCase      :      Any         =InstructBlipProcessor(
											    tokenizer=self.get_tokenizer()						,    image_processor=self.get_image_processor()						,    qformer_tokenizer=self.get_qformer_tokenizer()						,    )
											processor.save_pretrained(self.tmpdirname			)

											__lowerCamelCase      :      List[str]         =self.get_tokenizer(bos_token='''(BOS)'''						,    eos_token='''(EOS)'''			)
											__lowerCamelCase      :      Dict         =self.get_image_processor(do_normalize=__lowercase						,    padding_value=1.0			)

											__lowerCamelCase      :      Union[str, Any]         =InstructBlipProcessor.from_pretrained(
											    self.tmpdirname						,    bos_token='''(BOS)'''						,    eos_token='''(EOS)'''						,    do_normalize=__lowercase						,    padding_value=1.0			)

											self.assertEqual(processor.tokenizer.get_vocab()						,    tokenizer_add_kwargs.get_vocab()			)
											self.assertIsInstance(processor.tokenizer						,    __lowercase			)

											self.assertEqual(processor.image_processor.to_json_string()						,    image_processor_add_kwargs.to_json_string()			)
											self.assertIsInstance(processor.image_processor						,    __lowercase			)
											self.assertIsInstance(processor.qformer_tokenizer						,    __lowercase			)




				def 					__lowercase  (     self  :Optional[int]			):
											__lowerCamelCase      :      Tuple         =self.get_image_processor()
											__lowerCamelCase      :      Union[str, Any]         =self.get_tokenizer()
											__lowerCamelCase      :      Dict         =self.get_qformer_tokenizer()

											__lowerCamelCase      :      Optional[Any]         =InstructBlipProcessor(
											    tokenizer=__lowercase						,    image_processor=__lowercase						,    qformer_tokenizer=__lowercase			)

											__lowerCamelCase      :      str         =self.prepare_image_inputs()

											__lowerCamelCase      :      Tuple         =image_processor(__lowercase						,    return_tensors='''np'''			)
											__lowerCamelCase      :      Tuple         =processor(images=__lowercase						,    return_tensors='''np'''			)

											for key in input_feat_extract.keys():
																		self.assertAlmostEqual(input_feat_extract[key].sum()						,    input_processor[key].sum()						,    delta=1e-2			)




				def 					__lowercase  (     self  :Optional[int]			):
											__lowerCamelCase      :      str         =self.get_image_processor()
											__lowerCamelCase      :      Optional[int]         =self.get_tokenizer()
											__lowerCamelCase      :      Optional[Any]         =self.get_qformer_tokenizer()

											__lowerCamelCase      :      Dict         =InstructBlipProcessor(
											    tokenizer=__lowercase						,    image_processor=__lowercase						,    qformer_tokenizer=__lowercase			)

											__lowerCamelCase      :      Any         ='''lower newer'''

											__lowerCamelCase      :      Any         =processor(text=__lowercase			)

											__lowerCamelCase      :      Any         =tokenizer(__lowercase						,    return_token_type_ids=__lowercase			)
											__lowerCamelCase      :      str         =qformer_tokenizer(__lowercase						,    return_token_type_ids=__lowercase			)

											for key in encoded_tokens.keys():
																		self.assertListEqual(encoded_tokens[key]						,    encoded_processor[key]			)

											for key in encoded_tokens_qformer.keys():
																		self.assertListEqual(encoded_tokens_qformer[key]						,    encoded_processor['''qformer_''' + key]			)




				def 					__lowercase  (     self  :List[str]			):
											__lowerCamelCase      :      Union[str, Any]         =self.get_image_processor()
											__lowerCamelCase      :      int         =self.get_tokenizer()
											__lowerCamelCase      :      List[Any]         =self.get_qformer_tokenizer()

											__lowerCamelCase      :      Any         =InstructBlipProcessor(
											    tokenizer=__lowercase						,    image_processor=__lowercase						,    qformer_tokenizer=__lowercase			)

											__lowerCamelCase      :      List[str]         ='''lower newer'''
											__lowerCamelCase      :      Union[str, Any]         =self.prepare_image_inputs()

											__lowerCamelCase      :      Dict         =processor(text=__lowercase						,    images=__lowercase			)

											self.assertListEqual(
											    list(inputs.keys()			)						,    ['''input_ids''', '''attention_mask''', '''qformer_input_ids''', '''qformer_attention_mask''', '''pixel_values''']						,    )

											# test if it raises when no input is passed
											with pytest.raises(__lowercase			):
																		processor()




				def 					__lowercase  (     self  :List[str]			):
											__lowerCamelCase      :      int         =self.get_image_processor()
											__lowerCamelCase      :      Optional[int]         =self.get_tokenizer()
											__lowerCamelCase      :      Optional[int]         =self.get_qformer_tokenizer()

											__lowerCamelCase      :      Dict         =InstructBlipProcessor(
											    tokenizer=__lowercase						,    image_processor=__lowercase						,    qformer_tokenizer=__lowercase			)

											__lowerCamelCase      :      Dict         =[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

											__lowerCamelCase      :      int         =processor.batch_decode(__lowercase			)
											__lowerCamelCase      :      Any         =tokenizer.batch_decode(__lowercase			)

											self.assertListEqual(__lowercase						,    __lowercase			)




				def 					__lowercase  (     self  :str			):
											__lowerCamelCase      :      str         =self.get_image_processor()
											__lowerCamelCase      :      Any         =self.get_tokenizer()
											__lowerCamelCase      :      Dict         =self.get_qformer_tokenizer()

											__lowerCamelCase      :      Union[str, Any]         =InstructBlipProcessor(
											    tokenizer=__lowercase						,    image_processor=__lowercase						,    qformer_tokenizer=__lowercase			)

											__lowerCamelCase      :      List[Any]         ='''lower newer'''
											__lowerCamelCase      :      Any         =self.prepare_image_inputs()

											__lowerCamelCase      :      Optional[Any]         =processor(text=__lowercase						,    images=__lowercase			)

											self.assertListEqual(
											    list(inputs.keys()			)						,    ['''input_ids''', '''attention_mask''', '''qformer_input_ids''', '''qformer_attention_mask''', '''pixel_values''']						,    )











"""simple docstring"""





from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


_UpperCamelCase							=      logging.get_logger(__name__)

# General docstring
_UpperCamelCase							=      'RegNetConfig'

# Base docstring
_UpperCamelCase							=      'facebook/regnet-y-040'
_UpperCamelCase							=      [1, 1088, 7, 7]

# Image classification docstring
_UpperCamelCase							=      'facebook/regnet-y-040'
_UpperCamelCase							=      'tabby, tabby cat'

_UpperCamelCase							=      [
    'facebook/regnet-y-040',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]
class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""




				def __init__(     self  :Dict						,    __lowercase  :int						,    __lowercase  :int = 3						,    __lowercase  :int = 1						,    __lowercase  :int = 1						,    __lowercase  :Optional[str] = "relu"						,    **__lowercase  :int						,    ):
											super().__init__(**__lowercase			)
											# The padding and conv has been verified in
											# https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
											__lowerCamelCase      :      int         =tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2			)
											__lowerCamelCase      :      str         =tf.keras.layers.ConvaD(
											    filters=__lowercase						,    kernel_size=__lowercase						,    strides=__lowercase						,    padding='''VALID'''						,    groups=__lowercase						,    use_bias=__lowercase						,    name='''convolution'''						,    )
											__lowerCamelCase      :      str         =tf.keras.layers.BatchNormalization(epsilon=1e-5						,    momentum=0.9						,    name='''normalization'''			)
											__lowerCamelCase      :      Optional[int]         =ACTaFN[activation] if activation is not None else tf.identity




				def 					__lowercase  (     self  :Optional[int]						,    __lowercase  :Any			):
											__lowerCamelCase      :      str         =self.convolution(self.padding(__lowercase			)			)
											__lowerCamelCase      :      Optional[int]         =self.normalization(__lowercase			)
											__lowerCamelCase      :      Any         =self.activation(__lowercase			)
											return hidden_state

class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""




				def __init__(     self  :Union[str, Any]						,    __lowercase  :RegNetConfig						,    **__lowercase  :Any			):
											super().__init__(**__lowercase			)
											__lowerCamelCase      :      Tuple         =config.num_channels
											__lowerCamelCase      :      Union[str, Any]         =TFRegNetConvLayer(
											    out_channels=config.embedding_size						,    kernel_size=3						,    stride=2						,    activation=config.hidden_act						,    name='''embedder'''						,    )




				def 					__lowercase  (     self  :int						,    __lowercase  :List[str]			):
											__lowerCamelCase      :      int         =shape_list(__lowercase			)[1]
											if tf.executing_eagerly() and num_channels != self.num_channels:
																		raise ValueError(
																		    '''Make sure that the channel dimension of the pixel values match with the one set in the configuration.'''			)

											# When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
											# So change the input format from `NCHW` to `NHWC`.
											# shape = (batch_size, in_height, in_width, in_channels=num_channels)
											__lowerCamelCase      :      Union[str, Any]         =tf.transpose(__lowercase						,    perm=(0, 2, 3, 1)			)
											__lowerCamelCase      :      Optional[int]         =self.embedder(__lowercase			)
											return hidden_state

class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""




				def __init__(     self  :List[Any]						,    __lowercase  :int						,    __lowercase  :int = 2						,    **__lowercase  :Optional[int]			):
											super().__init__(**__lowercase			)
											__lowerCamelCase      :      int         =tf.keras.layers.ConvaD(
											    filters=__lowercase						,    kernel_size=1						,    strides=__lowercase						,    use_bias=__lowercase						,    name='''convolution'''			)
											__lowerCamelCase      :      List[str]         =tf.keras.layers.BatchNormalization(epsilon=1e-5						,    momentum=0.9						,    name='''normalization'''			)




				def 					__lowercase  (     self  :Optional[Any]						,    __lowercase  :tf.Tensor						,    __lowercase  :bool = False			):
											return self.normalization(self.convolution(__lowercase			)						,    training=__lowercase			)

class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""




				def __init__(     self  :Dict						,    __lowercase  :int						,    __lowercase  :int						,    **__lowercase  :List[str]			):
											super().__init__(**__lowercase			)
											__lowerCamelCase      :      int         =tf.keras.layers.GlobalAveragePoolingaD(keepdims=__lowercase						,    name='''pooler'''			)
											__lowerCamelCase      :      int         =[
											    tf.keras.layers.ConvaD(filters=__lowercase						,    kernel_size=1						,    activation='''relu'''						,    name='''attention.0'''			),
											    tf.keras.layers.ConvaD(filters=__lowercase						,    kernel_size=1						,    activation='''sigmoid'''						,    name='''attention.2'''			),
											]




				def 					__lowercase  (     self  :Dict						,    __lowercase  :Union[str, Any]			):
											# [batch_size, h, w, num_channels] -> [batch_size, 1, 1, num_channels]
											__lowerCamelCase      :      Any         =self.pooler(__lowercase			)
											for layer_module in self.attention:
																		__lowerCamelCase      :      Any         =layer_module(__lowercase			)
											__lowerCamelCase      :      Dict         =hidden_state * pooled
											return hidden_state

class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""




				def __init__(     self  :Optional[int]						,    __lowercase  :RegNetConfig						,    __lowercase  :int						,    __lowercase  :int						,    __lowercase  :int = 1						,    **__lowercase  :str			):
											super().__init__(**__lowercase			)
											__lowerCamelCase      :      Dict         =in_channels != out_channels or stride != 1
											__lowerCamelCase      :      int         =max(1						,    out_channels // config.groups_width			)
											__lowerCamelCase      :      List[str]         =(
											    TFRegNetShortCut(__lowercase						,    stride=__lowercase						,    name='''shortcut'''			)
											    if should_apply_shortcut
											    else tf.keras.layers.Activation('''linear'''						,    name='''shortcut'''			)
											)
											# `self.layers` instead of `self.layer` because that is a reserved argument.
											__lowerCamelCase      :      str         =[
											    TFRegNetConvLayer(__lowercase						,    kernel_size=1						,    activation=config.hidden_act						,    name='''layer.0'''			),
											    TFRegNetConvLayer(
											        __lowercase						,    stride=__lowercase						,    groups=__lowercase						,    activation=config.hidden_act						,    name='''layer.1'''			),
											    TFRegNetConvLayer(__lowercase						,    kernel_size=1						,    activation=__lowercase						,    name='''layer.2'''			),
											]
											__lowerCamelCase      :      Optional[int]         =ACTaFN[config.hidden_act]




				def 					__lowercase  (     self  :int						,    __lowercase  :Optional[int]			):
											__lowerCamelCase      :      List[Any]         =hidden_state
											for layer_module in self.layers:
																		__lowerCamelCase      :      str         =layer_module(__lowercase			)
											__lowerCamelCase      :      List[Any]         =self.shortcut(__lowercase			)
											hidden_state += residual
											__lowerCamelCase      :      Optional[int]         =self.activation(__lowercase			)
											return hidden_state

class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""




				def __init__(     self  :Union[str, Any]						,    __lowercase  :RegNetConfig						,    __lowercase  :int						,    __lowercase  :int						,    __lowercase  :int = 1						,    **__lowercase  :List[str]			):
											super().__init__(**__lowercase			)
											__lowerCamelCase      :      Optional[Any]         =in_channels != out_channels or stride != 1
											__lowerCamelCase      :      Optional[Any]         =max(1						,    out_channels // config.groups_width			)
											__lowerCamelCase      :      Dict         =(
											    TFRegNetShortCut(__lowercase						,    stride=__lowercase						,    name='''shortcut'''			)
											    if should_apply_shortcut
											    else tf.keras.layers.Activation('''linear'''						,    name='''shortcut'''			)
											)
											__lowerCamelCase      :      Union[str, Any]         =[
											    TFRegNetConvLayer(__lowercase						,    kernel_size=1						,    activation=config.hidden_act						,    name='''layer.0'''			),
											    TFRegNetConvLayer(
											        __lowercase						,    stride=__lowercase						,    groups=__lowercase						,    activation=config.hidden_act						,    name='''layer.1'''			),
											    TFRegNetSELayer(__lowercase						,    reduced_channels=int(round(in_channels / 4			)			)						,    name='''layer.2'''			),
											    TFRegNetConvLayer(__lowercase						,    kernel_size=1						,    activation=__lowercase						,    name='''layer.3'''			),
											]
											__lowerCamelCase      :      Tuple         =ACTaFN[config.hidden_act]




				def 					__lowercase  (     self  :Tuple						,    __lowercase  :Tuple			):
											__lowerCamelCase      :      List[Any]         =hidden_state
											for layer_module in self.layers:
																		__lowerCamelCase      :      int         =layer_module(__lowercase			)
											__lowerCamelCase      :      List[str]         =self.shortcut(__lowercase			)
											hidden_state += residual
											__lowerCamelCase      :      List[str]         =self.activation(__lowercase			)
											return hidden_state

class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""




				def __init__(     self  :int						,    __lowercase  :RegNetConfig						,    __lowercase  :int						,    __lowercase  :int						,    __lowercase  :int = 2						,    __lowercase  :int = 2						,    **__lowercase  :Union[str, Any]			):
											super().__init__(**__lowercase			)

											__lowerCamelCase      :      List[str]         =TFRegNetXLayer if config.layer_type == '''x''' else TFRegNetYLayer
											__lowerCamelCase      :      List[Any]         =[
											    # downsampling is done in the first layer with stride of 2
											    layer(__lowercase						,    __lowercase						,    __lowercase						,    stride=__lowercase						,    name='''layers.0'''			),
											    *[layer(__lowercase						,    __lowercase						,    __lowercase						,    name=f'layers.{i+1}'			) for i in range(depth - 1			)],
											]




				def 					__lowercase  (     self  :int						,    __lowercase  :List[str]			):
											for layer_module in self.layers:
																		__lowerCamelCase      :      int         =layer_module(__lowercase			)
											return hidden_state

class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""




				def __init__(     self  :List[Any]						,    __lowercase  :RegNetConfig						,    **__lowercase  :List[str]			):
											super().__init__(**__lowercase			)
											__lowerCamelCase      :      Optional[int]         =[]
											# based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
											self.stages.append(
											    TFRegNetStage(
											        __lowercase						,    config.embedding_size						,    config.hidden_sizes[0]						,    stride=2 if config.downsample_in_first_stage else 1						,    depth=config.depths[0]						,    name='''stages.0'''						,    )			)
											__lowerCamelCase      :      Any         =zip(config.hidden_sizes						,    config.hidden_sizes[1:]			)
											for i, ((in_channels, out_channels), depth) in enumerate(zip(__lowercase						,    config.depths[1:]			)			):
																		self.stages.append(TFRegNetStage(__lowercase						,    __lowercase						,    __lowercase						,    depth=__lowercase						,    name=f'stages.{i+1}'			)			)




				def 					__lowercase  (     self  :str						,    __lowercase  :tf.Tensor						,    __lowercase  :bool = False						,    __lowercase  :bool = True			):
											__lowerCamelCase      :      Optional[Any]         =() if output_hidden_states else None

											for stage_module in self.stages:
																		if output_hidden_states:
																									__lowerCamelCase      :      Dict         =hidden_states + (hidden_state,)

																		__lowerCamelCase      :      List[Any]         =stage_module(__lowercase			)

											if output_hidden_states:
																		__lowerCamelCase      :      Union[str, Any]         =hidden_states + (hidden_state,)

											if not return_dict:
																		return tuple(v for v in [hidden_state, hidden_states] if v is not None			)

											return TFBaseModelOutputWithNoAttention(last_hidden_state=__lowercase						,    hidden_states=__lowercase			)

@keras_serializable
class 		SCREAMING_SNAKE_CASE_							(    tf.keras.layers.Layer   ):
				"""simple docstring"""
				__snake_case   :       Optional[int]	 =		RegNetConfig




				def __init__(     self  :List[Any]						,    __lowercase  :Dict						,    **__lowercase  :Union[str, Any]			):
											super().__init__(**__lowercase			)
											__lowerCamelCase      :      int         =config
											__lowerCamelCase      :      List[str]         =TFRegNetEmbeddings(__lowercase						,    name='''embedder'''			)
											__lowerCamelCase      :      List[str]         =TFRegNetEncoder(__lowercase						,    name='''encoder'''			)
											__lowerCamelCase      :      List[Any]         =tf.keras.layers.GlobalAveragePoolingaD(keepdims=__lowercase						,    name='''pooler'''			)




				@unpack_inputs
				def 					__lowercase  (     self  :List[Any]						,    __lowercase  :tf.Tensor						,    __lowercase  :Optional[bool] = None						,    __lowercase  :Optional[bool] = None						,    __lowercase  :bool = False						,    ):
											__lowerCamelCase      :      Union[str, Any]         =(
											    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
											)
											__lowerCamelCase      :      Tuple         =return_dict if return_dict is not None else self.config.use_return_dict

											__lowerCamelCase      :      Tuple         =self.embedder(__lowercase						,    training=__lowercase			)

											__lowerCamelCase      :      Optional[Any]         =self.encoder(
											    __lowercase						,    output_hidden_states=__lowercase						,    return_dict=__lowercase						,    training=__lowercase			)

											__lowerCamelCase      :      str         =encoder_outputs[0]
											__lowerCamelCase      :      Tuple         =self.pooler(__lowercase			)

											# Change to NCHW output format have uniformity in the modules
											__lowerCamelCase      :      int         =tf.transpose(__lowercase						,    perm=(0, 3, 1, 2)			)
											__lowerCamelCase      :      Any         =tf.transpose(__lowercase						,    perm=(0, 3, 1, 2)			)

											# Change the other hidden state outputs to NCHW as well
											if output_hidden_states:
																		__lowerCamelCase      :      str         =tuple([tf.transpose(__lowercase						,    perm=(0, 3, 1, 2)			) for h in encoder_outputs[1]]			)

											if not return_dict:
																		return (last_hidden_state, pooled_output) + encoder_outputs[1:]

											return TFBaseModelOutputWithPoolingAndNoAttention(
											    last_hidden_state=__lowercase						,    pooler_output=__lowercase						,    hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states						,    )

class 		SCREAMING_SNAKE_CASE_							(    snake_case__   ):
				"""simple docstring"""
				__snake_case   :       Optional[int]	 =		RegNetConfig
				__snake_case   :       int	 =		"""regnet"""
				__snake_case   :       int	 =		"""pixel_values"""




				@property
				def 					__lowercase  (     self  :List[str]			):
											return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)						,    dtype=tf.floataa			)}

_UpperCamelCase							=      r'\n    Parameters:\n    This model is a Tensorflow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular Tensorflow Module and refer to the Tensorflow documentation for all matter related to general usage and\n    behavior.\n        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n'

_UpperCamelCase							=      r'\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConveNextImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'
@add_start_docstrings(
    """The bare RegNet model outputting raw features without any specific head on top."""       ,  snake_case__       ,  )
class 		SCREAMING_SNAKE_CASE_							(    snake_case__   ):
				"""simple docstring"""




				def __init__(     self  :Union[str, Any]						,    __lowercase  :RegNetConfig						,    *__lowercase  :List[str]						,    **__lowercase  :int			):
											super().__init__(__lowercase						,    *__lowercase						,    **__lowercase			)
											__lowerCamelCase      :      Tuple         =TFRegNetMainLayer(__lowercase						,    name='''regnet'''			)




				@unpack_inputs
				@add_start_docstrings_to_model_forward(__lowercase			)
				@add_code_sample_docstrings(
				    checkpoint=_CHECKPOINT_FOR_DOC						,    output_type=__lowercase						,    config_class=_CONFIG_FOR_DOC						,    modality='''vision'''						,    expected_output=_EXPECTED_OUTPUT_SHAPE						,    )
				def 					__lowercase  (     self  :Optional[Any]						,    __lowercase  :tf.Tensor						,    __lowercase  :Optional[bool] = None						,    __lowercase  :Optional[bool] = None						,    __lowercase  :Optional[int]=False						,    ):
											__lowerCamelCase      :      List[Any]         =(
											    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
											)
											__lowerCamelCase      :      Optional[int]         =return_dict if return_dict is not None else self.config.use_return_dict

											__lowerCamelCase      :      Dict         =self.regnet(
											    pixel_values=__lowercase						,    output_hidden_states=__lowercase						,    return_dict=__lowercase						,    training=__lowercase						,    )
											if not return_dict:
																		return (outputs[0],) + outputs[1:]

											return TFBaseModelOutputWithPoolingAndNoAttention(
											    last_hidden_state=outputs.last_hidden_state						,    pooler_output=outputs.pooler_output						,    hidden_states=outputs.hidden_states						,    )

@add_start_docstrings(
    """
    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    """       ,  snake_case__       ,  )
class 		SCREAMING_SNAKE_CASE_							(    snake_case__       ,  snake_case__   ):
				"""simple docstring"""




				def __init__(     self  :Union[str, Any]						,    __lowercase  :RegNetConfig						,    *__lowercase  :List[Any]						,    **__lowercase  :Dict			):
											super().__init__(__lowercase						,    *__lowercase						,    **__lowercase			)
											__lowerCamelCase      :      Optional[int]         =config.num_labels
											__lowerCamelCase      :      Optional[int]         =TFRegNetMainLayer(__lowercase						,    name='''regnet'''			)
											# classification head
											__lowerCamelCase      :      Union[str, Any]         =[
											    tf.keras.layers.Flatten(),
											    tf.keras.layers.Dense(config.num_labels						,    name='''classifier.1'''			) if config.num_labels > 0 else tf.identity,
											]




				@unpack_inputs
				@add_start_docstrings_to_model_forward(__lowercase			)
				@add_code_sample_docstrings(
				    checkpoint=_IMAGE_CLASS_CHECKPOINT						,    output_type=__lowercase						,    config_class=_CONFIG_FOR_DOC						,    expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT						,    )
				def 					__lowercase  (     self  :List[Any]						,    __lowercase  :tf.Tensor = None						,    __lowercase  :tf.Tensor = None						,    __lowercase  :bool = None						,    __lowercase  :bool = None						,    __lowercase  :int=False						,    ):
											__lowerCamelCase      :      str         =(
											    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
											)
											__lowerCamelCase      :      Optional[int]         =return_dict if return_dict is not None else self.config.use_return_dict

											__lowerCamelCase      :      str         =self.regnet(
											    __lowercase						,    output_hidden_states=__lowercase						,    return_dict=__lowercase						,    training=__lowercase			)

											__lowerCamelCase      :      Any         =outputs.pooler_output if return_dict else outputs[1]

											__lowerCamelCase      :      List[str]         =self.classifier[0](__lowercase			)
											__lowerCamelCase      :      str         =self.classifier[1](__lowercase			)

											__lowerCamelCase      :      str         =None if labels is None else self.hf_compute_loss(labels=__lowercase						,    logits=__lowercase			)

											if not return_dict:
																		__lowerCamelCase      :      Optional[int]         =(logits,) + outputs[2:]
																		return ((loss,) + output) if loss is not None else output

											return TFSequenceClassifierOutput(loss=__lowercase						,    logits=__lowercase						,    hidden_states=outputs.hidden_states			)




