
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_						:     Any	       =							logging.get_logger(__name__)

# General docstring
UpperCamelCase_						:     Union[str, Any]	       =							"""RegNetConfig"""

# Base docstring
UpperCamelCase_						:     str	       =							"""facebook/regnet-y-040"""
UpperCamelCase_						:     Dict	       =							[1, 1088, 7, 7]

# Image classification docstring
UpperCamelCase_						:     int	       =							"""facebook/regnet-y-040"""
UpperCamelCase_						:     Optional[int]	       =							"""tabby, tabby cat"""

UpperCamelCase_						:     List[Any]	       =							[
    """facebook/regnet-y-040""",
    # See all regnet models at https://huggingface.co/models?filter=regnet
]




class   __lowercase						(						tf.keras.layers.Layer       ):






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






	def       _a(self				: List[Any]      ,	snake_case				: List[str]    ) ->			Optional[int]:
							_lowercase       :	str           =   self.convolution(self.padding(snake_case    )    )
							_lowercase       :	Union[str, Any]           =   self.normalization(snake_case    )
							_lowercase       :	int           =   self.activation(snake_case    )
							return hidden_state




class   __lowercase						(						tf.keras.layers.Layer       ):






	def __init__(self				: Optional[int]      ,	snake_case				: RegNetConfig      ,	**snake_case				: Any    ) ->			Dict:
							super().__init__(**snake_case    )
							_lowercase       :	List[str]           =   config.num_channels
							_lowercase       :	List[str]           =   TFRegNetConvLayer(
							    out_channels=config.embedding_size      ,	kernel_size=3      ,	stride=2      ,	activation=config.hidden_act      ,	name="embedder"      ,	)






	def       _a(self				: List[Any]      ,	snake_case				: Optional[Any]    ) ->			Any:
							_lowercase       :	Union[str, Any]           =   shape_list(snake_case    )[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)
							_lowercase       :	str           =   tf.transpose(snake_case      ,	perm=(0, 2, 3, 1)    )
							_lowercase       :	Dict           =   self.embedder(snake_case    )
							return hidden_state




class   __lowercase						(						tf.keras.layers.Layer       ):






	def __init__(self				: Union[str, Any]      ,	snake_case				: int      ,	snake_case				: int = 2      ,	**snake_case				: int    ) ->			Optional[int]:
							super().__init__(**snake_case    )
							_lowercase       :	Dict           =   tf.keras.layers.ConvaD(
							    filters=snake_case      ,	kernel_size=1      ,	strides=snake_case      ,	use_bias=snake_case      ,	name="convolution"    )
							_lowercase       :	Any           =   tf.keras.layers.BatchNormalization(epsilon=1e-5      ,	momentum=0.9      ,	name="normalization"    )






	def       _a(self				: List[str]      ,	snake_case				: tf.Tensor      ,	snake_case				: bool = False    ) ->			tf.Tensor:
							return self.normalization(self.convolution(snake_case    )      ,	training=snake_case    )




class   __lowercase						(						tf.keras.layers.Layer       ):






	def __init__(self				: Any      ,	snake_case				: int      ,	snake_case				: int      ,	**snake_case				: Optional[Any]    ) ->			List[Any]:
							super().__init__(**snake_case    )
							_lowercase       :	Tuple           =   tf.keras.layers.GlobalAveragePoolingaD(keepdims=snake_case      ,	name="pooler"    )
							_lowercase       :	Optional[Any]           =   [
							    tf.keras.layers.ConvaD(filters=snake_case      ,	kernel_size=1      ,	activation="relu"      ,	name="attention.0"    ),
							    tf.keras.layers.ConvaD(filters=snake_case      ,	kernel_size=1      ,	activation="sigmoid"      ,	name="attention.2"    ),
							]






	def       _a(self				: Any      ,	snake_case				: Optional[int]    ) ->			Optional[int]:
							# [batch_size, h, w, num_channels] -> [batch_size, 1, 1, num_channels]
							_lowercase       :	Any           =   self.pooler(snake_case    )
							for layer_module in self.attention:
													_lowercase       :	int           =   layer_module(snake_case    )
							_lowercase       :	Dict           =   hidden_state * pooled
							return hidden_state




class   __lowercase						(						tf.keras.layers.Layer       ):






	def __init__(self				: Optional[int]      ,	snake_case				: RegNetConfig      ,	snake_case				: int      ,	snake_case				: int      ,	snake_case				: int = 1      ,	**snake_case				: Optional[int]    ) ->			Dict:
							super().__init__(**snake_case    )
							_lowercase       :	Tuple           =   in_channels != out_channels or stride != 1
							_lowercase       :	Tuple           =   max(1      ,	out_channels // config.groups_width    )
							_lowercase       :	Tuple           =   (
							    TFRegNetShortCut(snake_case      ,	stride=snake_case      ,	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.
							_lowercase       :	List[str]           =   [
							    TFRegNetConvLayer(snake_case      ,	kernel_size=1      ,	activation=config.hidden_act      ,	name="layer.0"    ),
							    TFRegNetConvLayer(
							        snake_case      ,	stride=snake_case      ,	groups=snake_case      ,	activation=config.hidden_act      ,	name="layer.1"    ),
							    TFRegNetConvLayer(snake_case      ,	kernel_size=1      ,	activation=snake_case      ,	name="layer.2"    ),
							]
							_lowercase       :	Any           =   ACTaFN[config.hidden_act]






	def       _a(self				: str      ,	snake_case				: int    ) ->			int:
							_lowercase       :	str           =   hidden_state
							for layer_module in self.layers:
													_lowercase       :	Dict           =   layer_module(snake_case    )
							_lowercase       :	int           =   self.shortcut(snake_case    )
							hidden_state += residual
							_lowercase       :	str           =   self.activation(snake_case    )
							return hidden_state




class   __lowercase						(						tf.keras.layers.Layer       ):






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






	def       _a(self				: Dict      ,	snake_case				: str    ) ->			str:
							_lowercase       :	List[str]           =   hidden_state
							for layer_module in self.layers:
													_lowercase       :	List[str]           =   layer_module(snake_case    )
							_lowercase       :	Any           =   self.shortcut(snake_case    )
							hidden_state += residual
							_lowercase       :	List[str]           =   self.activation(snake_case    )
							return hidden_state




class   __lowercase						(						tf.keras.layers.Layer       ):






	def __init__(self				: Dict      ,	snake_case				: RegNetConfig      ,	snake_case				: int      ,	snake_case				: int      ,	snake_case				: int = 2      ,	snake_case				: int = 2      ,	**snake_case				: Any    ) ->			Dict:
							super().__init__(**snake_case    )

							_lowercase       :	Optional[int]           =   TFRegNetXLayer if config.layer_type == "x" else TFRegNetYLayer
							_lowercase       :	List[str]           =   [
							    # downsampling is done in the first layer with stride of 2
							    layer(snake_case      ,	snake_case      ,	snake_case      ,	stride=snake_case      ,	name="layers.0"    ),
							    *[layer(snake_case      ,	snake_case      ,	snake_case      ,	name=F"""layers.{i+1}"""    ) for i in range(depth - 1    )],
							]






	def       _a(self				: List[Any]      ,	snake_case				: Tuple    ) ->			List[str]:
							for layer_module in self.layers:
													_lowercase       :	Dict           =   layer_module(snake_case    )
							return hidden_state




class   __lowercase						(						tf.keras.layers.Layer       ):






	def __init__(self				: str      ,	snake_case				: RegNetConfig      ,	**snake_case				: str    ) ->			Dict:
							super().__init__(**snake_case    )
							_lowercase       :	Any           =   []
							# based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
							self.stages.append(
							    TFRegNetStage(
							        snake_case      ,	config.embedding_size      ,	config.hidden_sizes[0]      ,	stride=2 if config.downsample_in_first_stage else 1      ,	depth=config.depths[0]      ,	name="stages.0"      ,	)    )
							_lowercase       :	Union[str, Any]           =   zip(config.hidden_sizes      ,	config.hidden_sizes[1:]    )
							for i, ((in_channels, out_channels), depth) in enumerate(zip(snake_case      ,	config.depths[1:]    )    ):
													self.stages.append(TFRegNetStage(snake_case      ,	snake_case      ,	snake_case      ,	depth=snake_case      ,	name=F"""stages.{i+1}"""    )    )






	def       _a(self				: str      ,	snake_case				: tf.Tensor      ,	snake_case				: bool = False      ,	snake_case				: bool = True    ) ->			TFBaseModelOutputWithNoAttention:
							_lowercase       :	int           =   () if output_hidden_states else None

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

													_lowercase       :	int           =   stage_module(snake_case    )

							if output_hidden_states:
													_lowercase       :	str           =   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=snake_case      ,	hidden_states=snake_case    )




@keras_serializable
class   __lowercase						(						tf.keras.layers.Layer       ):
	_A       =   RegNetConfig






	def __init__(self				: List[Any]      ,	snake_case				: Any      ,	**snake_case				: Any    ) ->			Tuple:
							super().__init__(**snake_case    )
							_lowercase       :	Optional[Any]           =   config
							_lowercase       :	Dict           =   TFRegNetEmbeddings(snake_case      ,	name="embedder"    )
							_lowercase       :	Dict           =   TFRegNetEncoder(snake_case      ,	name="encoder"    )
							_lowercase       :	Dict           =   tf.keras.layers.GlobalAveragePoolingaD(keepdims=snake_case      ,	name="pooler"    )






	@unpack_inputs
	def       _a(self				: Optional[int]      ,	snake_case				: tf.Tensor      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Optional[bool] = None      ,	snake_case				: bool = False      ,	) ->			TFBaseModelOutputWithPoolingAndNoAttention:
							_lowercase       :	Any           =   (
							    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
							)
							_lowercase       :	int           =   return_dict if return_dict is not None else self.config.use_return_dict

							_lowercase       :	Dict           =   self.embedder(snake_case      ,	training=snake_case    )

							_lowercase       :	Optional[Any]           =   self.encoder(
							    snake_case      ,	output_hidden_states=snake_case      ,	return_dict=snake_case      ,	training=snake_case    )

							_lowercase       :	int           =   encoder_outputs[0]
							_lowercase       :	Any           =   self.pooler(snake_case    )

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

							# Change the other hidden state outputs to NCHW as well
							if output_hidden_states:
													_lowercase       :	str           =   tuple([tf.transpose(snake_case      ,	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=snake_case      ,	pooler_output=snake_case      ,	hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states      ,	)




class   __lowercase						(						__snake_case       ):
	_A       =   RegNetConfig
	_A       =   "regnet"
	_A       =   "pixel_values"






	@property
	def       _a(self				: Optional[int]    ) ->			Optional[int]:
							return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)      ,	dtype=tf.floataa    )}


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

UpperCamelCase_						:     str	       =							R"""
    Args:
        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConveNextImageProcessor.__call__`] for details.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
"""




@add_start_docstrings(
    "The bare RegNet model outputting raw features without any specific head on top."   , __snake_case   , )
class   __lowercase						(						__snake_case       ):






	def __init__(self				: Optional[int]      ,	snake_case				: RegNetConfig      ,	*snake_case				: Optional[int]      ,	**snake_case				: Optional[Any]    ) ->			Tuple:
							super().__init__(snake_case      ,	*snake_case      ,	**snake_case    )
							_lowercase       :	List[str]           =   TFRegNetMainLayer(snake_case      ,	name="regnet"    )






	@unpack_inputs
	@add_start_docstrings_to_model_forward(snake_case    )
	@add_code_sample_docstrings(
	    checkpoint=_CHECKPOINT_FOR_DOC      ,	output_type=snake_case      ,	config_class=_CONFIG_FOR_DOC      ,	modality="vision"      ,	expected_output=_EXPECTED_OUTPUT_SHAPE      ,	)
	def       _a(self				: Any      ,	snake_case				: tf.Tensor      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Optional[bool] = None      ,	snake_case				: int=False      ,	) ->			Union[TFBaseModelOutputWithPoolingAndNoAttention, Tuple[tf.Tensor]]:
							_lowercase       :	Tuple           =   (
							    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
							)
							_lowercase       :	List[Any]           =   return_dict if return_dict is not None else self.config.use_return_dict

							_lowercase       :	Tuple           =   self.regnet(
							    pixel_values=snake_case      ,	output_hidden_states=snake_case      ,	return_dict=snake_case      ,	training=snake_case      ,	)
							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(
    "\n    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    "   , __snake_case   , )
class   __lowercase						(						__snake_case   , __snake_case       ):






	def __init__(self				: Any      ,	snake_case				: RegNetConfig      ,	*snake_case				: Union[str, Any]      ,	**snake_case				: Any    ) ->			Optional[int]:
							super().__init__(snake_case      ,	*snake_case      ,	**snake_case    )
							_lowercase       :	Dict           =   config.num_labels
							_lowercase       :	Dict           =   TFRegNetMainLayer(snake_case      ,	name="regnet"    )
							# classification head
							_lowercase       :	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(snake_case    )
	@add_code_sample_docstrings(
	    checkpoint=_IMAGE_CLASS_CHECKPOINT      ,	output_type=snake_case      ,	config_class=_CONFIG_FOR_DOC      ,	expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT      ,	)
	def       _a(self				: str      ,	snake_case				: tf.Tensor = None      ,	snake_case				: tf.Tensor = None      ,	snake_case				: bool = None      ,	snake_case				: bool = None      ,	snake_case				: Dict=False      ,	) ->			Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]:
							_lowercase       :	List[str]           =   (
							    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
							)
							_lowercase       :	Any           =   return_dict if return_dict is not None else self.config.use_return_dict

							_lowercase       :	Dict           =   self.regnet(
							    snake_case      ,	output_hidden_states=snake_case      ,	return_dict=snake_case      ,	training=snake_case    )

							_lowercase       :	str           =   outputs.pooler_output if return_dict else outputs[1]

							_lowercase       :	List[str]           =   self.classifier[0](snake_case    )
							_lowercase       :	Dict           =   self.classifier[1](snake_case    )

							_lowercase       :	Optional[Any]           =   None if labels is None else self.hf_compute_loss(labels=snake_case      ,	logits=snake_case    )

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

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






from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging


if is_torch_available():
							import torch


UpperCamelCase_						:     Tuple	       =							logging.get_logger(__name__)




class   __lowercase						(						__snake_case       ):
	_A       =   ["pixel_values"]






	def __init__(self				: List[str]      ,	snake_case				: bool = True      ,	snake_case				: Optional[Dict[str, int]] = None      ,	snake_case				: PILImageResampling = PILImageResampling.BILINEAR      ,	snake_case				: bool = True      ,	snake_case				: Dict[str, int] = None      ,	snake_case				: bool = True      ,	snake_case				: Union[int, float] = 1 / 255      ,	snake_case				: bool = True      ,	snake_case				: Optional[Union[float, List[float]]] = None      ,	snake_case				: Optional[Union[float, List[float]]] = None      ,	**snake_case				: List[Any]      ,	) ->			None:
							super().__init__(**snake_case    )
							_lowercase       :	List[str]           =   size if size is not None else {"shortest_edge": 256}
							_lowercase       :	Union[str, Any]           =   get_size_dict(snake_case      ,	default_to_square=snake_case    )
							_lowercase       :	List[str]           =   crop_size if crop_size is not None else {"height": 224, "width": 224}
							_lowercase       :	Dict           =   get_size_dict(snake_case      ,	param_name="crop_size"    )
							_lowercase       :	List[Any]           =   do_resize
							_lowercase       :	Optional[Any]           =   size
							_lowercase       :	Tuple           =   resample
							_lowercase       :	Tuple           =   do_center_crop
							_lowercase       :	Any           =   crop_size
							_lowercase       :	str           =   do_rescale
							_lowercase       :	int           =   rescale_factor
							_lowercase       :	List[Any]           =   do_normalize
							_lowercase       :	List[str]           =   image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
							_lowercase       :	Optional[Any]           =   image_std if image_std is not None else IMAGENET_STANDARD_STD






	def       _a(self				: Tuple      ,	snake_case				: np.ndarray      ,	snake_case				: Dict[str, int]      ,	snake_case				: PILImageResampling = PILImageResampling.BICUBIC      ,	snake_case				: Optional[Union[str, ChannelDimension]] = None      ,	**snake_case				: int      ,	) ->			np.ndarray:
							_lowercase       :	Union[str, Any]           =   get_size_dict(snake_case      ,	default_to_square=snake_case    )
							if "shortest_edge" not in size:
													raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""    )
							_lowercase       :	int           =   get_resize_output_image_size(snake_case      ,	size=size["shortest_edge"]      ,	default_to_square=snake_case    )
							return resize(snake_case      ,	size=snake_case      ,	resample=snake_case      ,	data_format=snake_case      ,	**snake_case    )






	def       _a(self				: str      ,	snake_case				: np.ndarray      ,	snake_case				: Dict[str, int]      ,	snake_case				: Optional[Union[str, ChannelDimension]] = None      ,	**snake_case				: Union[str, Any]      ,	) ->			np.ndarray:
							_lowercase       :	Union[str, Any]           =   get_size_dict(snake_case    )
							if "height" not in size or "width" not in size:
													raise ValueError(F"""The `size` parameter must contain the keys `height` and `width`. Got {size.keys()}"""    )
							return center_crop(snake_case      ,	size=(size["height"], size["width"])      ,	data_format=snake_case      ,	**snake_case    )






	def       _a(self				: Union[str, Any]      ,	snake_case				: np.ndarray      ,	snake_case				: float      ,	snake_case				: Optional[Union[str, ChannelDimension]] = None      ,	**snake_case				: List[Any]    ) ->			np.ndarray:
							return rescale(snake_case      ,	scale=snake_case      ,	data_format=snake_case      ,	**snake_case    )






	def       _a(self				: int      ,	snake_case				: np.ndarray      ,	snake_case				: Union[float, List[float]]      ,	snake_case				: Union[float, List[float]]      ,	snake_case				: Optional[Union[str, ChannelDimension]] = None      ,	**snake_case				: Tuple      ,	) ->			np.ndarray:
							return normalize(snake_case      ,	mean=snake_case      ,	std=snake_case      ,	data_format=snake_case      ,	**snake_case    )






	def       _a(self				: Optional[int]      ,	snake_case				: ImageInput      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Dict[str, int] = None      ,	snake_case				: PILImageResampling = None      ,	snake_case				: bool = None      ,	snake_case				: Dict[str, int] = None      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Optional[float] = None      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Optional[Union[float, List[float]]] = None      ,	snake_case				: Optional[Union[float, List[float]]] = None      ,	snake_case				: Optional[Union[str, TensorType]] = None      ,	snake_case				: Union[str, ChannelDimension] = ChannelDimension.FIRST      ,	**snake_case				: Tuple      ,	) ->			Union[str, Any]:
							_lowercase       :	Any           =   do_resize if do_resize is not None else self.do_resize
							_lowercase       :	List[str]           =   size if size is not None else self.size
							_lowercase       :	Optional[int]           =   get_size_dict(snake_case      ,	default_to_square=snake_case    )
							_lowercase       :	Tuple           =   resample if resample is not None else self.resample
							_lowercase       :	List[Any]           =   do_center_crop if do_center_crop is not None else self.do_center_crop
							_lowercase       :	int           =   crop_size if crop_size is not None else self.crop_size
							_lowercase       :	Dict           =   get_size_dict(snake_case      ,	param_name="crop_size"    )
							_lowercase       :	Dict           =   do_rescale if do_rescale is not None else self.do_rescale
							_lowercase       :	List[Any]           =   rescale_factor if rescale_factor is not None else self.rescale_factor
							_lowercase       :	Union[str, Any]           =   do_normalize if do_normalize is not None else self.do_normalize
							_lowercase       :	Dict           =   image_mean if image_mean is not None else self.image_mean
							_lowercase       :	Optional[Any]           =   image_std if image_std is not None else self.image_std

							_lowercase       :	int           =   make_list_of_images(snake_case    )

							if not valid_images(snake_case    ):
													raise ValueError(
													    "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
													    "torch.Tensor, tf.Tensor or jax.ndarray."    )

							if do_resize and size is None:
													raise ValueError("Size must be specified if do_resize is True."    )

							if do_center_crop and crop_size is None:
													raise ValueError("Crop size must be specified if do_center_crop is True."    )

							if do_rescale and rescale_factor is None:
													raise ValueError("Rescale factor must be specified if do_rescale is True."    )

							if do_normalize and (image_mean is None or image_std is None):
													raise ValueError("Image mean and std must be specified if do_normalize is True."    )

							# All transformations expect numpy arrays.
							_lowercase       :	Tuple           =   [to_numpy_array(snake_case    ) for image in images]

							if do_resize:
													_lowercase       :	List[str]           =   [self.resize(image=snake_case      ,	size=snake_case      ,	resample=snake_case    ) for image in images]

							if do_center_crop:
													_lowercase       :	List[str]           =   [self.center_crop(image=snake_case      ,	size=snake_case    ) for image in images]

							if do_rescale:
													_lowercase       :	Any           =   [self.rescale(image=snake_case      ,	scale=snake_case    ) for image in images]

							if do_normalize:
													_lowercase       :	Optional[Any]           =   [self.normalize(image=snake_case      ,	mean=snake_case      ,	std=snake_case    ) for image in images]

							_lowercase       :	Any           =   [to_channel_dimension_format(snake_case      ,	snake_case    ) for image in images]

							_lowercase       :	Optional[Any]           =   {"pixel_values": images}
							return BatchFeature(data=snake_case      ,	tensor_type=snake_case    )






	def       _a(self				: Dict      ,	snake_case				: List[str]      ,	snake_case				: List[Tuple] = None    ) ->			Optional[Any]:
							_lowercase       :	Dict           =   outputs.logits

							# Resize logits and compute semantic segmentation maps
							if target_sizes is not None:
													if len(snake_case    ) != len(snake_case    ):
																			raise ValueError(
																			    "Make sure that you pass in as many target sizes as the batch dimension of the logits"    )

													if is_torch_tensor(snake_case    ):
																			_lowercase       :	Dict           =   target_sizes.numpy()

													_lowercase       :	Tuple           =   []

													for idx in range(len(snake_case    )    ):
																			_lowercase       :	List[str]           =   torch.nn.functional.interpolate(
																			    logits[idx].unsqueeze(dim=0    )      ,	size=target_sizes[idx]      ,	mode="bilinear"      ,	align_corners=snake_case    )
																			_lowercase       :	int           =   resized_logits[0].argmax(dim=0    )
																			semantic_segmentation.append(snake_case    )
							else:
													_lowercase       :	Optional[int]           =   logits.argmax(dim=1    )
													_lowercase       :	int           =   [semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]    )]

							return semantic_segmentation




