





from typing import List, Optional, Tuple, Union

import torch
from torch import nn
from torch.nn import CrossEntropyLoss

from ... import AutoBackbone
from ...modeling_outputs import SemanticSegmenterOutput
from ...modeling_utils import PreTrainedModel
from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
from ...utils.backbone_utils import BackboneMixin
from .configuration_upernet import UperNetConfig


__lowercase       :List[Any]       =  [
    'openmmlab/upernet-convnext-tiny',
    # See all UperNet models at https://huggingface.co/models?filter=upernet
]

# General docstring
__lowercase       :str       =  'UperNetConfig'



class    _a     (				nn.Module							):






							"""simple docstring"""

							def __init__(      self				:     Tuple							,	a				:     int							,	a				:     int							,	a				:     Union[int, Tuple[int, int]]							,	a				:     Union[int, Tuple[int, int], str] = 0							,	a				:     bool = False							,	a				:     Union[int, Tuple[int, int]] = 1							,	)	->None:
													super().__init__()
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					nn.Convad(
													    in_channels=a							,	out_channels=a							,	kernel_size=a							,	padding=a							,	bias=a							,	dilation=a							,	)
													SCREAMING_SNAKE_CASE__     :				Any   =					nn.BatchNormad(a    )
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					nn.ReLU()






							def      A_  (      self				:     List[str]							,	a				:     torch.Tensor    )	->torch.Tensor:
													SCREAMING_SNAKE_CASE__     :				int   =					self.conv(a    )
													SCREAMING_SNAKE_CASE__     :				Any   =					self.batch_norm(a    )
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					self.activation(a    )

													return output







class    _a     (				nn.Module							):






							"""simple docstring"""

							def __init__(      self				:     List[str]							,	a				:     int							,	a				:     int							,	a				:     int    )	->None:
													super().__init__()
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					[
													    nn.AdaptiveAvgPoolad(a    ),
													    UperNetConvModule(a							,	a							,	kernel_size=1    ),
													]
													for i, layer in enumerate(self.layers    ):
																			self.add_module(str(a    )							,	a    )






							def      A_  (      self				:     Union[str, Any]							,	a				:     torch.Tensor    )	->torch.Tensor:
													SCREAMING_SNAKE_CASE__     :				Tuple   =					input
													for layer in self.layers:
																			SCREAMING_SNAKE_CASE__     :				Dict   =					layer(a    )
													return hidden_state







class    _a     (				nn.Module							):






							"""simple docstring"""

							def __init__(      self				:     Dict							,	a				:     Tuple[int, ...]							,	a				:     int							,	a				:     int							,	a				:     bool    )	->None:
													super().__init__()
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					pool_scales
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					align_corners
													SCREAMING_SNAKE_CASE__     :				List[str]   =					in_channels
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					channels
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					[]
													for i, pool_scale in enumerate(a    ):
																			SCREAMING_SNAKE_CASE__     :				str   =					UperNetPyramidPoolingBlock(pool_scale=a							,	in_channels=a							,	channels=a    )
																			self.blocks.append(a    )
																			self.add_module(str(a    )							,	a    )






							def      A_  (      self				:     List[str]							,	a				:     torch.Tensor    )	->List[torch.Tensor]:
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					[]
													for ppm in self.blocks:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					ppm(a    )
																			SCREAMING_SNAKE_CASE__     :				str   =					nn.functional.interpolate(
																			    a							,	size=x.size()[2:]							,	mode="bilinear"							,	align_corners=self.align_corners    )
																			ppm_outs.append(a    )
													return ppm_outs







class    _a     (				nn.Module							):






							"""simple docstring"""

							def __init__(      self				:     List[Any]							,	a				:     Any							,	a				:     Optional[Any]    )	->int:
													super().__init__()

													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					config
													SCREAMING_SNAKE_CASE__     :				str   =					config.pool_scales  # e.g. (1, 2, 3, 6)
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					in_channels
													SCREAMING_SNAKE_CASE__     :				List[str]   =					config.hidden_size
													SCREAMING_SNAKE_CASE__     :				int   =					False
													SCREAMING_SNAKE_CASE__     :				str   =					nn.Convad(self.channels							,	config.num_labels							,	kernel_size=1    )

													# PSP Module
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					UperNetPyramidPoolingModule(
													    self.pool_scales							,	self.in_channels[-1]							,	self.channels							,	align_corners=self.align_corners							,	)
													SCREAMING_SNAKE_CASE__     :				Tuple   =					UperNetConvModule(
													    self.in_channels[-1] + len(self.pool_scales    ) * self.channels							,	self.channels							,	kernel_size=3							,	padding=1							,	)
													# FPN Module
													SCREAMING_SNAKE_CASE__     :				Any   =					nn.ModuleList()
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					nn.ModuleList()
													for in_channels in self.in_channels[:-1]:  # skip the top layer
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					UperNetConvModule(a							,	self.channels							,	kernel_size=1    )
																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					UperNetConvModule(self.channels							,	self.channels							,	kernel_size=3							,	padding=1    )
																			self.lateral_convs.append(a    )
																			self.fpn_convs.append(a    )

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					UperNetConvModule(
													    len(self.in_channels    ) * self.channels							,	self.channels							,	kernel_size=3							,	padding=1							,	)

							def      A_  (      self				:     Tuple    )	->List[str]:
													self.apply(self._init_weights    )

							def      A_  (      self				:     str							,	a				:     int    )	->Tuple:
													if isinstance(a							,	nn.Convad    ):
																			module.weight.data.normal_(mean=0.0							,	std=self.config.initializer_range    )
																			if module.bias is not None:
																									module.bias.data.zero_()

							def      A_  (      self				:     List[str]							,	a				:     List[str]    )	->int:
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					inputs[-1]
													SCREAMING_SNAKE_CASE__     :				Tuple   =					[x]
													psp_outs.extend(self.psp_modules(a    )    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					torch.cat(a							,	dim=1    )
													SCREAMING_SNAKE_CASE__     :				Any   =					self.bottleneck(a    )

													return output






							def      A_  (      self				:     List[Any]							,	a				:     torch.Tensor    )	->torch.Tensor:
													# build laterals
													SCREAMING_SNAKE_CASE__     :				List[str]   =					[lateral_conv(encoder_hidden_states[i]    ) for i, lateral_conv in enumerate(self.lateral_convs    )]

													laterals.append(self.psp_forward(a    )    )

													# build top-down path
													SCREAMING_SNAKE_CASE__     :				str   =					len(a    )
													for i in range(used_backbone_levels - 1							,	0							,	-1    ):
																			SCREAMING_SNAKE_CASE__     :				str   =					laterals[i - 1].shape[2:]
																			SCREAMING_SNAKE_CASE__     :				int   =					laterals[i - 1] + nn.functional.interpolate(
																			    laterals[i]							,	size=a							,	mode="bilinear"							,	align_corners=self.align_corners    )

													# build outputs
													SCREAMING_SNAKE_CASE__     :				int   =					[self.fpn_convs[i](laterals[i]    ) for i in range(used_backbone_levels - 1    )]
													# append psp feature
													fpn_outs.append(laterals[-1]    )

													for i in range(used_backbone_levels - 1							,	0							,	-1    ):
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					nn.functional.interpolate(
																			    fpn_outs[i]							,	size=fpn_outs[0].shape[2:]							,	mode="bilinear"							,	align_corners=self.align_corners    )
													SCREAMING_SNAKE_CASE__     :				Any   =					torch.cat(a							,	dim=1    )
													SCREAMING_SNAKE_CASE__     :				int   =					self.fpn_bottleneck(a    )
													SCREAMING_SNAKE_CASE__     :				int   =					self.classifier(a    )

													return output







class    _a     (				nn.Module							):






							"""simple docstring"""

							def __init__(      self				:     Any							,	a				:     Any							,	a				:     int = 2							,	a				:     int = 3							,	a				:     Union[int, Tuple[int, int]] = 1    )	->None:
													super().__init__()

													SCREAMING_SNAKE_CASE__     :				int   =					config
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					config.auxiliary_in_channels
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					config.auxiliary_channels
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					config.auxiliary_num_convs
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					config.auxiliary_concat_input
													SCREAMING_SNAKE_CASE__     :				str   =					in_index

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					(kernel_size // 2) * dilation
													SCREAMING_SNAKE_CASE__     :				Any   =					[]
													convs.append(
													    UperNetConvModule(
													        self.in_channels							,	self.channels							,	kernel_size=a							,	padding=a							,	dilation=a    )    )
													for i in range(self.num_convs - 1    ):
																			convs.append(
																			    UperNetConvModule(
																			        self.channels							,	self.channels							,	kernel_size=a							,	padding=a							,	dilation=a    )    )
													if self.num_convs == 0:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					nn.Identity()
													else:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					nn.Sequential(*a    )
													if self.concat_input:
																			SCREAMING_SNAKE_CASE__     :				Any   =					UperNetConvModule(
																			    self.in_channels + self.channels							,	self.channels							,	kernel_size=a							,	padding=kernel_size // 2    )

													SCREAMING_SNAKE_CASE__     :				Tuple   =					nn.Convad(self.channels							,	config.num_labels							,	kernel_size=1    )

							def      A_  (      self				:     List[Any]    )	->List[str]:
													self.apply(self._init_weights    )

							def      A_  (      self				:     Optional[int]							,	a				:     Dict    )	->List[str]:
													if isinstance(a							,	nn.Convad    ):
																			module.weight.data.normal_(mean=0.0							,	std=self.config.initializer_range    )
																			if module.bias is not None:
																									module.bias.data.zero_()






							def      A_  (      self				:     Union[str, Any]							,	a				:     torch.Tensor    )	->torch.Tensor:
													# just take the relevant feature maps
													SCREAMING_SNAKE_CASE__     :				str   =					encoder_hidden_states[self.in_index]
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					self.convs(a    )
													if self.concat_input:
																			SCREAMING_SNAKE_CASE__     :				int   =					self.conv_cat(torch.cat([hidden_states, output]							,	dim=1    )    )
													SCREAMING_SNAKE_CASE__     :				str   =					self.classifier(a    )
													return output







class    _a     (				__lowercase							):






							"""simple docstring"""

							snake_case_							 =						UperNetConfig
							snake_case_							 =						"pixel_values"
							snake_case_							 =						True

							def      A_  (      self				:     Tuple							,	a				:     List[Any]    )	->Optional[Any]:
													if isinstance(a							,	a    ):
																			module.backbone.init_weights()
																			module.decode_head.init_weights()
																			module.auxiliary_head.init_weights()

							def      A_  (      self				:     Dict    )	->Any:
													self.backbone.init_weights()
													self.decode_head.init_weights()
													self.auxiliary_head.init_weights()






							def      A_  (      self				:     List[str]							,	a				:     List[Any]							,	a				:     Optional[Any]=False    )	->Union[str, Any]:
													if isinstance(a							,	a    ):
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					value







__lowercase       :Dict       =  R'\n    Parameters:\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use\n    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n        config ([`UperNetConfig`]): 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'

__lowercase       :Dict       =  R'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using\n            [`AutoImageProcessor`]. See [`SegformerImageProcessor.__call__`] for details.\n        output_attentions (`bool`, *optional*):\n            Whether or not to return the attentions tensors of all attention layers in case the backbone has them. See\n            `attentions` under returned tensors for more detail.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers of the backbone. See `hidden_states` under\n            returned tensors for 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(
    "UperNet framework leveraging any vision backbone e.g. for ADE20k, CityScapes."					,							__lowercase					,							)
class    _a     (				__lowercase							):






							"""simple docstring"""

							def __init__(      self				:     int							,	a				:     Tuple    )	->List[str]:
													super().__init__(a    )

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					AutoBackbone.from_config(config.backbone_config    )

													# Semantic segmentation head(s)
													SCREAMING_SNAKE_CASE__     :				int   =					UperNetHead(a							,	in_channels=self.backbone.channels    )
													SCREAMING_SNAKE_CASE__     :				Any   =					UperNetFCNHead(a    ) if config.use_auxiliary_head else None

													# Initialize weights and apply final processing
													self.post_init()






							@add_start_docstrings_to_model_forward(UPERNET_INPUTS_DOCSTRING.format("batch_size, sequence_length"    )    )
							@replace_return_docstrings(output_type=a							,	config_class=_CONFIG_FOR_DOC    )
							def      A_  (      self				:     Any							,	a				:     Optional[torch.Tensor] = None							,	a				:     Optional[bool] = None							,	a				:     Optional[bool] = None							,	a				:     Optional[torch.Tensor] = None							,	a				:     Optional[bool] = None							,	)	->Union[tuple, SemanticSegmenterOutput]:
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					return_dict if return_dict is not None else self.config.use_return_dict
													SCREAMING_SNAKE_CASE__     :				Tuple   =					(
													    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
													)
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					output_attentions if output_attentions is not None else self.config.output_attentions

													SCREAMING_SNAKE_CASE__     :				int   =					self.backbone.forward_with_filtered_kwargs(
													    a							,	output_hidden_states=a							,	output_attentions=a    )
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					outputs.feature_maps

													SCREAMING_SNAKE_CASE__     :				str   =					self.decode_head(a    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					nn.functional.interpolate(a							,	size=pixel_values.shape[2:]							,	mode="bilinear"							,	align_corners=a    )

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					None
													if self.auxiliary_head is not None:
																			SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.auxiliary_head(a    )
																			SCREAMING_SNAKE_CASE__     :				List[str]   =					nn.functional.interpolate(
																			    a							,	size=pixel_values.shape[2:]							,	mode="bilinear"							,	align_corners=a    )

													SCREAMING_SNAKE_CASE__     :				int   =					None
													if labels is not None:
																			if self.config.num_labels == 1:
																									raise ValueError("The number of labels should be greater than one"    )
																			else:
																									# compute weighted loss
																									SCREAMING_SNAKE_CASE__     :				Any   =					CrossEntropyLoss(ignore_index=self.config.loss_ignore_index    )
																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					loss_fct(a							,	a    )
																									SCREAMING_SNAKE_CASE__     :				Optional[int]   =					loss_fct(a							,	a    )
																									SCREAMING_SNAKE_CASE__     :				Tuple   =					main_loss + self.config.auxiliary_loss_weight * auxiliary_loss

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

													return SemanticSegmenterOutput(
													    loss=a							,	logits=a							,	hidden_states=outputs.hidden_states							,	attentions=outputs.attentions							,	)






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

import numpy as np

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

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import BridgeTowerImageProcessor



class    _a     (				unittest.TestCase							):






							"""simple docstring"""

							def __init__(      self				:     Optional[int]							,	a				:     Any							,	a				:     bool = True							,	a				:     Dict[str, int] = None							,	a				:     int = 32							,	a				:     bool = True							,	a				:     Union[int, float] = 1 / 2_55							,	a				:     bool = True							,	a				:     bool = True							,	a				:     Optional[Union[float, List[float]]] = [0.4814_5466, 0.457_8275, 0.4082_1073]							,	a				:     Optional[Union[float, List[float]]] = [0.2686_2954, 0.2613_0258, 0.2757_7711]							,	a				:     bool = True							,	a				:     Any=7							,	a				:     str=30							,	a				:     Dict=4_00							,	a				:     Optional[int]=3							,	)	->int:
													SCREAMING_SNAKE_CASE__     :				int   =					parent
													SCREAMING_SNAKE_CASE__     :				Dict   =					do_resize
													SCREAMING_SNAKE_CASE__     :				List[str]   =					size if size is not None else {"shortest_edge": 2_88}
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					size_divisor
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					do_rescale
													SCREAMING_SNAKE_CASE__     :				Tuple   =					rescale_factor
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					do_normalize
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					do_center_crop
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					image_mean
													SCREAMING_SNAKE_CASE__     :				Dict   =					image_std
													SCREAMING_SNAKE_CASE__     :				List[str]   =					do_pad
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					batch_size
													SCREAMING_SNAKE_CASE__     :				int   =					num_channels
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					min_resolution
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					max_resolution

							def      A_  (      self				:     List[str]    )	->Tuple:
													return {
													    "image_mean": self.image_mean,
													    "image_std": self.image_std,
													    "do_normalize": self.do_normalize,
													    "do_resize": self.do_resize,
													    "size": self.size,
													    "size_divisor": self.size_divisor,
													}






							def      A_  (      self				:     int							,	a				:     Optional[int]							,	a				:     Union[str, Any]=False    )	->Optional[Any]:
													if not batched:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					self.size["shortest_edge"]
																			SCREAMING_SNAKE_CASE__     :				Dict   =					image_inputs[0]
																			if isinstance(a							,	Image.Image    ):
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Dict   =					image.size
																			else:
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				List[str]   =					image.shape[1], image.shape[2]
																			SCREAMING_SNAKE_CASE__     :				Any   =					size / min(a							,	a    )
																			if h < w:
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[int]   =					size, scale * w
																			else:
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				List[str]   =					scale * h, size

																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					int((13_33 / 8_00) * size    )
																			if max(a							,	a    ) > max_size:
																									SCREAMING_SNAKE_CASE__     :				List[Any]   =					max_size / max(a							,	a    )
																									SCREAMING_SNAKE_CASE__     :				int   =					newh * scale
																									SCREAMING_SNAKE_CASE__     :				Optional[int]   =					neww * scale

																			SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Any   =					int(newh + 0.5    ), int(neww + 0.5    )
																			SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Any   =					(
																			    newh // self.size_divisor * self.size_divisor,
																			    neww // self.size_divisor * self.size_divisor,
																			)

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

													return expected_height, expected_width







@require_torch
@require_vision
class    _a     (				lowercase__					,							unittest.TestCase							):






							"""simple docstring"""

							snake_case_							 =						BridgeTowerImageProcessor if is_vision_available() else None

							def      A_  (      self				:     List[Any]    )	->Union[str, Any]:
													SCREAMING_SNAKE_CASE__     :				Any   =					BridgeTowerImageProcessingTester(self    )

							@property
							def      A_  (      self				:     Optional[int]    )	->Optional[Any]:
													return self.image_processor_tester.prepare_image_processor_dict()

							def      A_  (      self				:     Tuple    )	->str:
													SCREAMING_SNAKE_CASE__     :				int   =					self.image_processing_class(**self.image_processor_dict    )
													self.assertTrue(hasattr(a							,	"image_mean"    )    )
													self.assertTrue(hasattr(a							,	"image_std"    )    )
													self.assertTrue(hasattr(a							,	"do_normalize"    )    )
													self.assertTrue(hasattr(a							,	"do_resize"    )    )
													self.assertTrue(hasattr(a							,	"size"    )    )
													self.assertTrue(hasattr(a							,	"size_divisor"    )    )

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

							def      A_  (      self				:     Tuple    )	->Optional[Any]:
													# Initialize image processor
													SCREAMING_SNAKE_CASE__     :				Dict   =					self.image_processing_class(**self.image_processor_dict    )
													# create random PIL images
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					prepare_image_inputs(self.image_processor_tester							,	equal_resolution=a    )
													for image in image_inputs:
																			self.assertIsInstance(a							,	Image.Image    )

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

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.image_processor_tester.get_expected_values(a    )
													self.assertEqual(
													    encoded_images.shape							,	(1, self.image_processor_tester.num_channels, expected_height, expected_width)							,	)

													# Test batched
													SCREAMING_SNAKE_CASE__     :				int   =					image_processing(a							,	return_tensors="pt"    ).pixel_values

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Any   =					self.image_processor_tester.get_expected_values(a							,	batched=a    )
													self.assertEqual(
													    encoded_images.shape							,	(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_channels,
													        expected_height,
													        expected_width,
													    )							,	)

							def      A_  (      self				:     Optional[int]    )	->Any:
													# Initialize image processor
													SCREAMING_SNAKE_CASE__     :				str   =					self.image_processing_class(**self.image_processor_dict    )
													# create random numpy tensors
													SCREAMING_SNAKE_CASE__     :				str   =					prepare_image_inputs(self.image_processor_tester							,	equal_resolution=a							,	numpify=a    )
													for image in image_inputs:
																			self.assertIsInstance(a							,	np.ndarray    )

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

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				List[Any]   =					self.image_processor_tester.get_expected_values(a    )
													self.assertEqual(
													    encoded_images.shape							,	(1, self.image_processor_tester.num_channels, expected_height, expected_width)							,	)

													# Test batched
													SCREAMING_SNAKE_CASE__     :				Tuple   =					image_processing(a							,	return_tensors="pt"    ).pixel_values

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					self.image_processor_tester.get_expected_values(a							,	batched=a    )
													self.assertEqual(
													    encoded_images.shape							,	(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_channels,
													        expected_height,
													        expected_width,
													    )							,	)






							def      A_  (      self				:     str    )	->Optional[int]:
													# Initialize image processor
													SCREAMING_SNAKE_CASE__     :				Dict   =					self.image_processing_class(**self.image_processor_dict    )
													# create random PyTorch tensors
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					prepare_image_inputs(self.image_processor_tester							,	equal_resolution=a							,	torchify=a    )
													for image in image_inputs:
																			self.assertIsInstance(a							,	torch.Tensor    )

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

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Tuple   =					self.image_processor_tester.get_expected_values(a    )
													self.assertEqual(
													    encoded_images.shape							,	(1, self.image_processor_tester.num_channels, expected_height, expected_width)							,	)

													# Test batched
													SCREAMING_SNAKE_CASE__     :				Any   =					image_processing(a							,	return_tensors="pt"    ).pixel_values

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.image_processor_tester.get_expected_values(a							,	batched=a    )
													self.assertEqual(
													    encoded_images.shape							,	(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_channels,
													        expected_height,
													        expected_width,
													    )							,	)