from typing import Optional

import torch
import torch.utils.checkpoint
from torch import Tensor, nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_outputs import (
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import logging
from .configuration_regnet import RegNetConfig


__lowerCamelCase      :			Union[str, Any]							       =		logging.get_logger(__name__)

# General docstring
__lowerCamelCase      :			Optional[Any]							       =		'RegNetConfig'

# Base docstring
__lowerCamelCase      :			List[str]							       =		'facebook/regnet-y-040'
__lowerCamelCase      :			Optional[Any]							       =		[1, 1088, 7, 7]

# Image classification docstring
__lowerCamelCase      :			Any							       =		'facebook/regnet-y-040'
__lowerCamelCase      :			List[str]							       =		'tabby, tabby cat'

__lowerCamelCase      :			Union[str, Any]							       =		[
    'facebook/regnet-y-040',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]







class __snake_case    (						nn.Module		):




			def __init__(   self      :    Tuple	,     _lowercase      :    Dict	,     _lowercase      :    int	,     _lowercase      :    Tuple = 3	,     _lowercase      :    Optional[int] = 1	,     _lowercase      :    Union[str, Any] = 1	,     _lowercase      :    Tuple = "relu"	,     ):



					"""simple docstring"""






					super().__init__()
					SCREAMING_SNAKE_CASE__      							=				nn.Convad(
					    _SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     kernel_size=_SCREAMING_SNAKE_CASE	,     stride=_SCREAMING_SNAKE_CASE	,     padding=kernel_size // 2	,     groups=_SCREAMING_SNAKE_CASE	,     bias=_SCREAMING_SNAKE_CASE	,     )
					SCREAMING_SNAKE_CASE__      							=				nn.BatchNormad(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				ACTaFN[activation] if activation is not None else nn.Identity()




			def      __a						(   self      :    Tuple	,     _lowercase      :    str				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				self.convolution(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				self.normalization(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				self.activation(_SCREAMING_SNAKE_CASE				)
					return hidden_state







class __snake_case    (						nn.Module		):




			def __init__(   self      :    Union[str, Any]	,     _lowercase      :    Optional[int]				):



					"""simple docstring"""






					super().__init__()
					SCREAMING_SNAKE_CASE__      							=				RegNetConvLayer(
					    config.num_channels	,     config.embedding_size	,     kernel_size=3	,     stride=2	,     activation=config.hidden_act				)
					SCREAMING_SNAKE_CASE__      							=				config.num_channels




			def      __a						(   self      :    Any	,     _lowercase      :    Any				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				pixel_values.shape[1]
					if 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."""				)
					SCREAMING_SNAKE_CASE__      							=				self.embedder(_SCREAMING_SNAKE_CASE				)
					return hidden_state







class __snake_case    (						nn.Module		):




			def __init__(   self      :    Optional[int]	,     _lowercase      :    Any	,     _lowercase      :    Tuple	,     _lowercase      :    Optional[int] = 2				):



					"""simple docstring"""






					super().__init__()
					SCREAMING_SNAKE_CASE__      							=				nn.Convad(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     kernel_size=1	,     stride=_SCREAMING_SNAKE_CASE	,     bias=_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				nn.BatchNormad(_SCREAMING_SNAKE_CASE				)




			def      __a						(   self      :    Any	,     _lowercase      :    List[str]				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				self.convolution(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				self.normalization(_SCREAMING_SNAKE_CASE				)
					return hidden_state







class __snake_case    (						nn.Module		):




			def __init__(   self      :    Optional[int]	,     _lowercase      :    int	,     _lowercase      :    Dict				):



					"""simple docstring"""






					super().__init__()

					SCREAMING_SNAKE_CASE__      							=				nn.AdaptiveAvgPoolad((1, 1)				)
					SCREAMING_SNAKE_CASE__      							=				nn.Sequential(
					    nn.Convad(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     kernel_size=1				)	,     nn.ReLU()	,     nn.Convad(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     kernel_size=1				)	,     nn.Sigmoid()	,     )




			def      __a						(   self      :    List[Any]	,     _lowercase      :    Union[str, Any]				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				self.pooler(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				self.attention(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				hidden_state * attention
					return hidden_state







class __snake_case    (						nn.Module		):




			def __init__(   self      :    Tuple	,     _lowercase      :    List[Any]	,     _lowercase      :    Dict	,     _lowercase      :    Any	,     _lowercase      :    Optional[int] = 1				):



					"""simple docstring"""






					super().__init__()
					SCREAMING_SNAKE_CASE__      							=				in_channels != out_channels or stride != 1
					SCREAMING_SNAKE_CASE__      							=				max(1	,     out_channels // config.groups_width				)
					SCREAMING_SNAKE_CASE__      							=				(
					    RegNetShortCut(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     stride=_SCREAMING_SNAKE_CASE				) if should_apply_shortcut else nn.Identity()
					)
					SCREAMING_SNAKE_CASE__      							=				nn.Sequential(
					    RegNetConvLayer(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     kernel_size=1	,     activation=config.hidden_act				)	,     RegNetConvLayer(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     stride=_SCREAMING_SNAKE_CASE	,     groups=_SCREAMING_SNAKE_CASE	,     activation=config.hidden_act				)	,     RegNetConvLayer(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     kernel_size=1	,     activation=_SCREAMING_SNAKE_CASE				)	,     )
					SCREAMING_SNAKE_CASE__      							=				ACTaFN[config.hidden_act]




			def      __a						(   self      :    Optional[int]	,     _lowercase      :    List[Any]				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				hidden_state
					SCREAMING_SNAKE_CASE__      							=				self.layer(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				self.shortcut(_SCREAMING_SNAKE_CASE				)
					hidden_state += residual
					SCREAMING_SNAKE_CASE__      							=				self.activation(_SCREAMING_SNAKE_CASE				)
					return hidden_state







class __snake_case    (						nn.Module		):




			def __init__(   self      :    Any	,     _lowercase      :    Optional[Any]	,     _lowercase      :    Optional[int]	,     _lowercase      :    Optional[int]	,     _lowercase      :    Dict = 1				):



					"""simple docstring"""






					super().__init__()
					SCREAMING_SNAKE_CASE__      							=				in_channels != out_channels or stride != 1
					SCREAMING_SNAKE_CASE__      							=				max(1	,     out_channels // config.groups_width				)
					SCREAMING_SNAKE_CASE__      							=				(
					    RegNetShortCut(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     stride=_SCREAMING_SNAKE_CASE				) if should_apply_shortcut else nn.Identity()
					)
					SCREAMING_SNAKE_CASE__      							=				nn.Sequential(
					    RegNetConvLayer(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     kernel_size=1	,     activation=config.hidden_act				)	,     RegNetConvLayer(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     stride=_SCREAMING_SNAKE_CASE	,     groups=_SCREAMING_SNAKE_CASE	,     activation=config.hidden_act				)	,     RegNetSELayer(_SCREAMING_SNAKE_CASE	,     reduced_channels=int(round(in_channels / 4				)				)				)	,     RegNetConvLayer(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     kernel_size=1	,     activation=_SCREAMING_SNAKE_CASE				)	,     )
					SCREAMING_SNAKE_CASE__      							=				ACTaFN[config.hidden_act]




			def      __a						(   self      :    Any	,     _lowercase      :    Any				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				hidden_state
					SCREAMING_SNAKE_CASE__      							=				self.layer(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				self.shortcut(_SCREAMING_SNAKE_CASE				)
					hidden_state += residual
					SCREAMING_SNAKE_CASE__      							=				self.activation(_SCREAMING_SNAKE_CASE				)
					return hidden_state







class __snake_case    (						nn.Module		):




			def __init__(   self      :    Union[str, Any]	,     _lowercase      :    Tuple	,     _lowercase      :    int	,     _lowercase      :    Dict	,     _lowercase      :    Dict = 2	,     _lowercase      :    Dict = 2	,     ):



					"""simple docstring"""






					super().__init__()

					SCREAMING_SNAKE_CASE__      							=				RegNetXLayer if config.layer_type == """x""" else RegNetYLayer

					SCREAMING_SNAKE_CASE__      							=				nn.Sequential(
					    # downsampling is done in the first layer with stride of 2
					    layer(
					        _SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     stride=_SCREAMING_SNAKE_CASE	,     )	,     *[layer(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE				) for _ in range(depth - 1				)]	,     )




			def      __a						(   self      :    Tuple	,     _lowercase      :    List[str]				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				self.layers(_SCREAMING_SNAKE_CASE				)
					return hidden_state







class __snake_case    (						nn.Module		):




			def __init__(   self      :    Union[str, Any]	,     _lowercase      :    Optional[Any]				):



					"""simple docstring"""






					super().__init__()
					SCREAMING_SNAKE_CASE__      							=				nn.ModuleList([]				)
					# based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
					self.stages.append(
					    RegNetStage(
					        _SCREAMING_SNAKE_CASE	,     config.embedding_size	,     config.hidden_sizes[0]	,     stride=2 if config.downsample_in_first_stage else 1	,     depth=config.depths[0]	,     )				)
					SCREAMING_SNAKE_CASE__      							=				zip(config.hidden_sizes	,     config.hidden_sizes[1:]				)
					for (in_channels, out_channels), depth in zip(_SCREAMING_SNAKE_CASE	,     config.depths[1:]				):
							self.stages.append(RegNetStage(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE	,     depth=_SCREAMING_SNAKE_CASE				)				)




			def      __a						(   self      :    List[str]	,     _lowercase      :    Union[str, Any]	,     _lowercase      :    str = False	,     _lowercase      :    str = True				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				() if output_hidden_states else None

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

							SCREAMING_SNAKE_CASE__      							=				stage_module(_SCREAMING_SNAKE_CASE				)

					if output_hidden_states:
							SCREAMING_SNAKE_CASE__      							=				hidden_states + (hidden_state,)

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

					return BaseModelOutputWithNoAttention(last_hidden_state=_SCREAMING_SNAKE_CASE	,     hidden_states=_SCREAMING_SNAKE_CASE				)







class __snake_case    (						_UpperCamelCase		):
			lowerCAmelCase_														=							RegNetConfig
			lowerCAmelCase_														=							'regnet'
			lowerCAmelCase_														=							'pixel_values'
			lowerCAmelCase_														=							True




			def      __a						(   self      :    int	,     _lowercase      :    Optional[int]				):



					"""simple docstring"""






					if isinstance(_SCREAMING_SNAKE_CASE	,     nn.Convad				):
							nn.init.kaiming_normal_(module.weight	,     mode="""fan_out"""	,     nonlinearity="""relu"""				)
					elif isinstance(_SCREAMING_SNAKE_CASE	,     (nn.BatchNormad, nn.GroupNorm)				):
							nn.init.constant_(module.weight	,     1				)
							nn.init.constant_(module.bias	,     0				)




			def      __a						(   self      :    str	,     _lowercase      :    int	,     _lowercase      :    Union[str, Any]=False				):



					"""simple docstring"""






					if isinstance(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE				):
							SCREAMING_SNAKE_CASE__      							=				value





__lowerCamelCase      :			str							       =		R'\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it\n    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\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 [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'

__lowerCamelCase      :			Union[str, Any]							       =		R'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\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 [`~file_utils.ModelOutput`] instead of a plain tuple.\n'







@add_start_docstrings(
    "The bare RegNet model outputting raw features without any specific head on top."       ,		_UpperCamelCase       ,		)
# Copied from transformers.models.resnet.modeling_resnet.ResNetModel with RESNET->REGNET,ResNet->RegNet
class __snake_case    (						_UpperCamelCase		):




			def __init__(   self      :    int	,     _lowercase      :    Dict				):



					"""simple docstring"""






					super().__init__(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				config
					SCREAMING_SNAKE_CASE__      							=				RegNetEmbeddings(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				RegNetEncoder(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				nn.AdaptiveAvgPoolad((1, 1)				)
					# Initialize weights and apply final processing
					self.post_init()




			@add_start_docstrings_to_model_forward(_SCREAMING_SNAKE_CASE				)
			@add_code_sample_docstrings(
			    checkpoint=_CHECKPOINT_FOR_DOC	,     output_type=_SCREAMING_SNAKE_CASE	,     config_class=_CONFIG_FOR_DOC	,     modality="""vision"""	,     expected_output=_EXPECTED_OUTPUT_SHAPE	,     )
			def      __a						(   self      :    Dict	,     _lowercase      :    int	,     _lowercase      :    List[str] = None	,     _lowercase      :    Union[str, Any] = None				):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				(
					    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
					)
					SCREAMING_SNAKE_CASE__      							=				return_dict if return_dict is not None else self.config.use_return_dict

					SCREAMING_SNAKE_CASE__      							=				self.embedder(_SCREAMING_SNAKE_CASE				)

					SCREAMING_SNAKE_CASE__      							=				self.encoder(
					    _SCREAMING_SNAKE_CASE	,     output_hidden_states=_SCREAMING_SNAKE_CASE	,     return_dict=_SCREAMING_SNAKE_CASE				)

					SCREAMING_SNAKE_CASE__      							=				encoder_outputs[0]

					SCREAMING_SNAKE_CASE__      							=				self.pooler(_SCREAMING_SNAKE_CASE				)

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

					return BaseModelOutputWithPoolingAndNoAttention(
					    last_hidden_state=_SCREAMING_SNAKE_CASE	,     pooler_output=_SCREAMING_SNAKE_CASE	,     hidden_states=encoder_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    "       ,		_UpperCamelCase       ,		)
# Copied from transformers.models.resnet.modeling_resnet.ResNetForImageClassification with RESNET->REGNET,ResNet->RegNet,resnet->regnet
class __snake_case    (						_UpperCamelCase		):




			def __init__(   self      :    Union[str, Any]	,     _lowercase      :    Optional[int]				):



					"""simple docstring"""






					super().__init__(_SCREAMING_SNAKE_CASE				)
					SCREAMING_SNAKE_CASE__      							=				config.num_labels
					SCREAMING_SNAKE_CASE__      							=				RegNetModel(_SCREAMING_SNAKE_CASE				)
					# classification head
					SCREAMING_SNAKE_CASE__      							=				nn.Sequential(
					    nn.Flatten()	,     nn.Linear(config.hidden_sizes[-1]	,     config.num_labels				) if config.num_labels > 0 else nn.Identity()	,     )
					# initialize weights and apply final processing
					self.post_init()




			@add_start_docstrings_to_model_forward(_SCREAMING_SNAKE_CASE				)
			@add_code_sample_docstrings(
			    checkpoint=_IMAGE_CLASS_CHECKPOINT	,     output_type=_SCREAMING_SNAKE_CASE	,     config_class=_CONFIG_FOR_DOC	,     expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT	,     )
			def      __a						(   self      :    int	,     _lowercase      :    Tuple = None	,     _lowercase      :    str = None	,     _lowercase      :    Optional[Any] = None	,     _lowercase      :    str = None	,     ):



					"""simple docstring"""






					SCREAMING_SNAKE_CASE__      							=				return_dict if return_dict is not None else self.config.use_return_dict

					SCREAMING_SNAKE_CASE__      							=				self.regnet(_SCREAMING_SNAKE_CASE	,     output_hidden_states=_SCREAMING_SNAKE_CASE	,     return_dict=_SCREAMING_SNAKE_CASE				)

					SCREAMING_SNAKE_CASE__      							=				outputs.pooler_output if return_dict else outputs[1]

					SCREAMING_SNAKE_CASE__      							=				self.classifier(_SCREAMING_SNAKE_CASE				)

					SCREAMING_SNAKE_CASE__      							=				None

					if labels is not None:
							if self.config.problem_type is None:
									if self.num_labels == 1:
											SCREAMING_SNAKE_CASE__      							=				"""regression"""
									elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
											SCREAMING_SNAKE_CASE__      							=				"""single_label_classification"""
									else:
											SCREAMING_SNAKE_CASE__      							=				"""multi_label_classification"""
							if self.config.problem_type == "regression":
									SCREAMING_SNAKE_CASE__      							=				MSELoss()
									if self.num_labels == 1:
											SCREAMING_SNAKE_CASE__      							=				loss_fct(logits.squeeze()	,     labels.squeeze()				)
									else:
											SCREAMING_SNAKE_CASE__      							=				loss_fct(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE				)
							elif self.config.problem_type == "single_label_classification":
									SCREAMING_SNAKE_CASE__      							=				CrossEntropyLoss()
									SCREAMING_SNAKE_CASE__      							=				loss_fct(logits.view(-1	,     self.num_labels				)	,     labels.view(-1				)				)
							elif self.config.problem_type == "multi_label_classification":
									SCREAMING_SNAKE_CASE__      							=				BCEWithLogitsLoss()
									SCREAMING_SNAKE_CASE__      							=				loss_fct(_SCREAMING_SNAKE_CASE	,     _SCREAMING_SNAKE_CASE				)

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

					return ImageClassifierOutputWithNoAttention(loss=_SCREAMING_SNAKE_CASE	,     logits=_SCREAMING_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,
    flip_channel_order,
    get_resize_output_image_size,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, is_vision_available, logging


if is_vision_available():
   import PIL

if is_torch_available():
   import torch


__lowerCamelCase      :			int							       =		logging.get_logger(__name__)







class __snake_case    (						lowerCamelCase_		):
   lowerCAmelCase_														=							["pixel_values"]




   def __init__(   self      :    int	,     _lowercase      :    bool = True	,     _lowercase      :    Dict[str, int] = None	,     _lowercase      :    PILImageResampling = PILImageResampling.BILINEAR	,     _lowercase      :    bool = True	,     _lowercase      :    Union[int, float] = 1 / 2_55	,     _lowercase      :    bool = True	,     _lowercase      :    Dict[str, int] = None	,     _lowercase      :    bool = True	,     **_lowercase      :    List[Any]	,     ):



     """simple docstring"""






     super().__init__(**_lowercase				)
     SCREAMING_SNAKE_CASE__      							=				size if size is not None else {"""shortest_edge""": 2_24}
     SCREAMING_SNAKE_CASE__      							=				get_size_dict(_lowercase	,     default_to_square=_lowercase				)
     SCREAMING_SNAKE_CASE__      							=				crop_size if crop_size is not None else {"""height""": 2_56, """width""": 2_56}
     SCREAMING_SNAKE_CASE__      							=				get_size_dict(_lowercase	,     param_name="""crop_size"""				)

     SCREAMING_SNAKE_CASE__      							=				do_resize
     SCREAMING_SNAKE_CASE__      							=				size
     SCREAMING_SNAKE_CASE__      							=				resample
     SCREAMING_SNAKE_CASE__      							=				do_rescale
     SCREAMING_SNAKE_CASE__      							=				rescale_factor
     SCREAMING_SNAKE_CASE__      							=				do_center_crop
     SCREAMING_SNAKE_CASE__      							=				crop_size
     SCREAMING_SNAKE_CASE__      							=				do_flip_channel_order




   def      __a						(   self      :    List[Any]	,     _lowercase      :    np.ndarray	,     _lowercase      :    Dict[str, int]	,     _lowercase      :    PILImageResampling = PIL.Image.BILINEAR	,     _lowercase      :    Optional[Union[str, ChannelDimension]] = None	,     **_lowercase      :    str	,     ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				get_size_dict(_lowercase	,     default_to_square=_lowercase				)
     if "shortest_edge" not in size:
       raise ValueError(f"""The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}"""				)
     SCREAMING_SNAKE_CASE__      							=				get_resize_output_image_size(_lowercase	,     size=size["""shortest_edge"""]	,     default_to_square=_lowercase				)
     return resize(_lowercase	,     size=_lowercase	,     resample=_lowercase	,     data_format=_lowercase	,     **_lowercase				)




   def      __a						(   self      :    str	,     _lowercase      :    np.ndarray	,     _lowercase      :    Dict[str, int]	,     _lowercase      :    Optional[Union[str, ChannelDimension]] = None	,     **_lowercase      :    Any	,     ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				get_size_dict(_lowercase				)
     if "height" not in size or "width" not in size:
       raise ValueError(f"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}"""				)
     return center_crop(_lowercase	,     size=(size["""height"""], size["""width"""])	,     data_format=_lowercase	,     **_lowercase				)




   def      __a						(   self      :    Optional[Any]	,     _lowercase      :    np.ndarray	,     _lowercase      :    Union[int, float]	,     _lowercase      :    Optional[Union[str, ChannelDimension]] = None	,     **_lowercase      :    Any	,     ):



     """simple docstring"""






     return rescale(_lowercase	,     scale=_lowercase	,     data_format=_lowercase	,     **_lowercase				)




   def      __a						(   self      :    Tuple	,     _lowercase      :    np.ndarray	,     _lowercase      :    Optional[Union[str, ChannelDimension]] = None				):



     """simple docstring"""






     return flip_channel_order(_lowercase	,     data_format=_lowercase				)




   def      __a						(   self      :    List[str]	,     _lowercase      :    ImageInput	,     _lowercase      :    bool = None	,     _lowercase      :    Dict[str, int] = None	,     _lowercase      :    PILImageResampling = None	,     _lowercase      :    bool = None	,     _lowercase      :    float = None	,     _lowercase      :    bool = None	,     _lowercase      :    Dict[str, int] = None	,     _lowercase      :    bool = None	,     _lowercase      :    Optional[Union[str, TensorType]] = None	,     _lowercase      :    ChannelDimension = ChannelDimension.FIRST	,     **_lowercase      :    int	,     ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				do_resize if do_resize is not None else self.do_resize
     SCREAMING_SNAKE_CASE__      							=				resample if resample is not None else self.resample
     SCREAMING_SNAKE_CASE__      							=				do_rescale if do_rescale is not None else self.do_rescale
     SCREAMING_SNAKE_CASE__      							=				rescale_factor if rescale_factor is not None else self.rescale_factor
     SCREAMING_SNAKE_CASE__      							=				do_center_crop if do_center_crop is not None else self.do_center_crop
     SCREAMING_SNAKE_CASE__      							=				(
         do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
     )

     SCREAMING_SNAKE_CASE__      							=				size if size is not None else self.size
     SCREAMING_SNAKE_CASE__      							=				get_size_dict(_lowercase	,     default_to_square=_lowercase				)
     SCREAMING_SNAKE_CASE__      							=				crop_size if crop_size is not None else self.crop_size
     SCREAMING_SNAKE_CASE__      							=				get_size_dict(_lowercase	,     param_name="""crop_size"""				)

     SCREAMING_SNAKE_CASE__      							=				make_list_of_images(_lowercase				)

     if not valid_images(_lowercase				):
       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_rescale and rescale_factor is None:
       raise ValueError("""Rescale factor must be specified if do_rescale is True."""				)

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

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

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

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

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

     # the pretrained checkpoints assume images are BGR, not RGB
     if do_flip_channel_order:
       SCREAMING_SNAKE_CASE__      							=				[self.flip_channel_order(image=_lowercase				) for image in images]

     SCREAMING_SNAKE_CASE__      							=				[to_channel_dimension_format(_lowercase	,     _lowercase				) for image in images]

     SCREAMING_SNAKE_CASE__      							=				{"""pixel_values""": images}
     return BatchFeature(data=_lowercase	,     tensor_type=_lowercase				)




   def      __a						(   self      :    List[Any]	,     _lowercase      :    Dict	,     _lowercase      :    List[Tuple] = None				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				outputs.logits

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

       if is_torch_tensor(_lowercase				):
         SCREAMING_SNAKE_CASE__      							=				target_sizes.numpy()

       SCREAMING_SNAKE_CASE__      							=				[]

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

     return semantic_segmentation
