






'''simple docstring'''





import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation, MobileNetVaModel
				from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import MobileNetVaImageProcessor


class 							__a							(  __A						):





		'''simple docstring'''



		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.config_class(**self.inputs_dict       )
						self.parent.assertTrue(hasattr(UpperCamelCase__ ,    'tf_padding'       )       )
						self.parent.assertTrue(hasattr(UpperCamelCase__ ,    'depth_multiplier'       )       )






class 							__a							:





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__=13 ,    UpperCamelCase__=3 ,    UpperCamelCase__=32 ,    UpperCamelCase__=0.25 ,    UpperCamelCase__=8 ,    UpperCamelCase__=8 ,    UpperCamelCase__=6 ,    UpperCamelCase__=32 ,    UpperCamelCase__=True ,    UpperCamelCase__=True ,    UpperCamelCase__=True ,    UpperCamelCase__="relu6" ,    UpperCamelCase__=1280 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=0.02 ,    UpperCamelCase__=True ,    UpperCamelCase__=True ,    UpperCamelCase__=10 ,    UpperCamelCase__=None ,    ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   parent
						SCREAMING_SNAKE_CASE_   :	Dict													=   batch_size
						SCREAMING_SNAKE_CASE_   :	int													=   num_channels
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   image_size
						SCREAMING_SNAKE_CASE_   :	Tuple													=   depth_multiplier
						SCREAMING_SNAKE_CASE_   :	Dict													=   depth_divisible_by
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   min_depth
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   expand_ratio
						SCREAMING_SNAKE_CASE_   :	List[str]													=   tf_padding
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   output_stride
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   first_layer_is_expansion
						SCREAMING_SNAKE_CASE_   :	Dict													=   finegrained_output
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   hidden_act
						SCREAMING_SNAKE_CASE_   :	str													=   last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier       )
						SCREAMING_SNAKE_CASE_   :	int													=   classifier_dropout_prob
						SCREAMING_SNAKE_CASE_   :	int													=   use_labels
						SCREAMING_SNAKE_CASE_   :	Any													=   is_training
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   num_labels
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   initializer_range
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   scope


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   None
						SCREAMING_SNAKE_CASE_   :	Dict													=   None
						if self.use_labels:
										SCREAMING_SNAKE_CASE_   :	List[str]													=   ids_tensor([self.batch_size] ,    self.num_labels       )
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   ids_tensor([self.batch_size, self.image_size, self.image_size] ,    self.num_labels       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.get_config()

						return config, pixel_values, labels, pixel_labels


		def   __snake_case			(						self       ):
						return MobileNetVaConfig(
						    num_channels=self.num_channels ,    image_size=self.image_size ,    depth_multiplier=self.depth_multiplier ,    depth_divisible_by=self.depth_divisible_by ,    min_depth=self.min_depth ,    expand_ratio=self.expand_ratio ,    output_stride=self.output_stride ,    first_layer_is_expansion=self.first_layer_is_expansion ,    finegrained_output=self.finegrained_output ,    hidden_act=self.hidden_act ,    tf_padding=self.tf_padding ,    classifier_dropout_prob=self.classifier_dropout_prob ,    initializer_range=self.initializer_range ,    )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	int													=   MobileNetVaModel(config=UpperCamelCase__       )
						model.to(UpperCamelCase__       )
						model.eval()
						SCREAMING_SNAKE_CASE_   :	str													=   model(UpperCamelCase__       )
						self.parent.assertEqual(
						    result.last_hidden_state.shape ,    (
						        self.batch_size,
						        self.last_hidden_size,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    ) ,    )
						self.parent.assertEqual(
						    result.pooler_output.shape ,    (self.batch_size, self.last_hidden_size) ,    )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.num_labels
						SCREAMING_SNAKE_CASE_   :	int													=   MobileNetVaForImageClassification(UpperCamelCase__       )
						model.to(UpperCamelCase__       )
						model.eval()
						SCREAMING_SNAKE_CASE_   :	Tuple													=   model(UpperCamelCase__ ,    labels=UpperCamelCase__       )
						self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.num_labels)       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Any													=   self.num_labels
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   MobileNetVaForSemanticSegmentation(UpperCamelCase__       )
						model.to(UpperCamelCase__       )
						model.eval()
						SCREAMING_SNAKE_CASE_   :	Any													=   model(UpperCamelCase__       )
						self.parent.assertEqual(
						    result.logits.shape ,    (
						        self.batch_size,
						        self.num_labels,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    ) ,    )
						SCREAMING_SNAKE_CASE_   :	Dict													=   model(UpperCamelCase__ ,    labels=UpperCamelCase__       )
						self.parent.assertEqual(
						    result.logits.shape ,    (
						        self.batch_size,
						        self.num_labels,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    ) ,    )






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.prepare_config_and_inputs()
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   config_and_inputs
						SCREAMING_SNAKE_CASE_   :	List[str]													=   {'pixel_values': pixel_values}
						return config, inputs_dict






@require_torch
class 							__a							(  __A ,	__A ,	unittest.TestCase						):





		'''simple docstring'''



		UpperCAmelCase__      :				Any				    =						(
		    (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
		    if is_torch_available()
		    else ()
		)
		UpperCAmelCase__      :				Optional[int]				    =						(
		    {
		        """feature-extraction""": MobileNetVaModel,
		        """image-classification""": MobileNetVaForImageClassification,
		        """image-segmentation""": MobileNetVaForSemanticSegmentation,
		    }
		    if is_torch_available()
		    else {}
		)

		UpperCAmelCase__      :				Dict				    =						False
		UpperCAmelCase__      :				Optional[Any]				    =						False
		UpperCAmelCase__      :				Tuple				    =						False
		UpperCAmelCase__      :				Tuple				    =						False


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   MobileNetVaModelTester(self       )
						SCREAMING_SNAKE_CASE_   :	int													=   MobileNetVaConfigTester(self ,    config_class=UpperCamelCase__ ,    has_text_modality=UpperCamelCase__       )


		def   __snake_case			(						self       ):
						self.config_tester.run_common_tests()


		@unittest.skip(reason='MobileNetV2 does not use inputs_embeds'       )
		def   __snake_case			(						self       ):
						pass


		@unittest.skip(reason='MobileNetV2 does not support input and output embeddings'       )
		def   __snake_case			(						self       ):
						pass


		@unittest.skip(reason='MobileNetV2 does not output attentions'       )
		def   __snake_case			(						self       ):
						pass


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										SCREAMING_SNAKE_CASE_   :	List[Any]													=   model_class(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   inspect.signature(model.forward       )
										# signature.parameters is an OrderedDict => so arg_names order is deterministic
										SCREAMING_SNAKE_CASE_   :	int													=   [*signature.parameters.keys()]

										SCREAMING_SNAKE_CASE_   :	Optional[int]													=   ['pixel_values']
										self.assertListEqual(arg_names[:1] ,    UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	str													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						def check_hidden_states_output(UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	int													=   model_class(UpperCamelCase__       )
										model.to(UpperCamelCase__       )
										model.eval()

										with torch.no_grad():
														SCREAMING_SNAKE_CASE_   :	Any													=   model(**self._prepare_for_class(UpperCamelCase__ ,    UpperCamelCase__       )       )

										SCREAMING_SNAKE_CASE_   :	List[Any]													=   outputs.hidden_states

										SCREAMING_SNAKE_CASE_   :	Dict													=   16
										self.assertEqual(len(UpperCamelCase__       ) ,    UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										SCREAMING_SNAKE_CASE_   :	List[Any]													=   True
										check_hidden_states_output(UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       )

										# check that output_hidden_states also work using config
										del inputs_dict["output_hidden_states"]
										SCREAMING_SNAKE_CASE_   :	List[str]													=   True

										check_hidden_states_output(UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_semantic_segmentation(*UpperCamelCase__       )






		@slow
		def   __snake_case			(						self       ):
						for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										SCREAMING_SNAKE_CASE_   :	Tuple													=   MobileNetVaModel.from_pretrained(UpperCamelCase__       )
										self.assertIsNotNone(UpperCamelCase__       )






def 					_lowerCamelCase(			):





				'''simple docstring'''







				SCREAMING_SNAKE_CASE_   :	List[str]													=   Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'      )
				return image


@require_torch
@require_vision
class 							__a							(  unittest.TestCase						):





		'''simple docstring'''



		@cached_property
		def   __snake_case			(						self       ):
						return (
						    MobileNetVaImageProcessor.from_pretrained('google/mobilenet_v2_1.0_224'       ) if is_vision_available() else None
						)


		@slow
		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	str													=   MobileNetVaForImageClassification.from_pretrained('google/mobilenet_v2_1.0_224'       ).to(UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.default_image_processor
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   prepare_img()
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   image_processor(images=UpperCamelCase__ ,    return_tensors='pt'       ).to(UpperCamelCase__       )

						# forward pass
						with torch.no_grad():
										SCREAMING_SNAKE_CASE_   :	int													=   model(**UpperCamelCase__       )

						# verify the logits
						SCREAMING_SNAKE_CASE_   :	List[str]													=   torch.Size((1, 1001)       )
						self.assertEqual(outputs.logits.shape ,    UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Dict													=   torch.tensor([0.24_45, -1.19_93, 0.19_05]       ).to(UpperCamelCase__       )

						self.assertTrue(torch.allclose(outputs.logits[0, :3] ,    UpperCamelCase__ ,    atol=1E-4       )       )






		@slow
		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   MobileNetVaForSemanticSegmentation.from_pretrained('google/deeplabv3_mobilenet_v2_1.0_513'       )
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   model.to(UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	int													=   MobileNetVaImageProcessor.from_pretrained('google/deeplabv3_mobilenet_v2_1.0_513'       )

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   prepare_img()
						SCREAMING_SNAKE_CASE_   :	int													=   image_processor(images=UpperCamelCase__ ,    return_tensors='pt'       ).to(UpperCamelCase__       )

						# forward pass
						with torch.no_grad():
										SCREAMING_SNAKE_CASE_   :	List[str]													=   model(**UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   outputs.logits

						# verify the logits
						SCREAMING_SNAKE_CASE_   :	str													=   torch.Size((1, 21, 65, 65)       )
						self.assertEqual(logits.shape ,    UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Any													=   torch.tensor(
						    [
						        [[17.57_90, 17.75_81, 18.33_55], [18.32_57, 18.42_30, 18.89_73], [18.61_69, 18.86_50, 19.21_87]],
						        [[-2.15_95, -2.09_77, -2.37_41], [-2.42_26, -2.30_28, -2.68_35], [-2.78_19, -2.59_91, -2.77_06]],
						        [[4.20_58, 4.83_17, 4.76_38], [4.41_36, 5.03_61, 4.93_83], [4.50_28, 4.96_44, 4.87_34]],
						    ] ,    device=UpperCamelCase__ ,    )

						self.assertTrue(torch.allclose(logits[0, :3, :3, :3] ,    UpperCamelCase__ ,    atol=1E-4       )       )







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

import numpy as np

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


if is_torch_available():
				import torch

if is_vision_available():
				import PIL


A        =			logging.get_logger(__name__)



def 					_lowerCamelCase(			lowerCAmelCase__				:		np.ndarray    ,    lowerCAmelCase__				:		Union[int, Iterable[int]]    ,    lowerCAmelCase__				:		bool    ,    lowerCAmelCase__				:		int      ):





				'''simple docstring'''







				def constraint_to_multiple_of(lowerCAmelCase__				:		str    ,    lowerCAmelCase__				:		Optional[Any]    ,    lowerCAmelCase__				:		Optional[Any]=0    ,    lowerCAmelCase__				:		Any=None      ):
								SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   round(val / multiple      ) * multiple

								if max_val is not None and x > max_val:
												SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   math.floor(val / multiple      ) * multiple

								if x < min_val:
												SCREAMING_SNAKE_CASE_   :	Dict													=   math.ceil(val / multiple      ) * multiple

								return x

				SCREAMING_SNAKE_CASE_   :	str													=   (output_size, output_size) if isinstance(lowerCAmelCase__    ,    lowerCAmelCase__      ) else output_size

				SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Any													=   get_image_size(lowerCAmelCase__      )
				SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	List[str]													=   output_size

				# determine new height and width
				SCREAMING_SNAKE_CASE_   :	Optional[int]													=   output_height / input_height
				SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   output_width / input_width

				if keep_aspect_ratio:
								# scale as little as possible
								if abs(1 - scale_width      ) < abs(1 - scale_height      ):
												# fit width
												SCREAMING_SNAKE_CASE_   :	str													=   scale_width
								else:
												# fit height
												SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   scale_height

				SCREAMING_SNAKE_CASE_   :	Any													=   constraint_to_multiple_of(scale_height * input_height    ,    multiple=lowerCAmelCase__      )
				SCREAMING_SNAKE_CASE_   :	int													=   constraint_to_multiple_of(scale_width * input_width    ,    multiple=lowerCAmelCase__      )

				return (new_height, new_width)


class 							__a							(  __A						):





		'''simple docstring'''



		UpperCAmelCase__      :				List[Any]				    =						["""pixel_values"""]


		def __init__(						self ,    UpperCamelCase__ = True ,    UpperCamelCase__ = None ,    UpperCamelCase__ = PILImageResampling.BILINEAR ,    UpperCamelCase__ = False ,    UpperCamelCase__ = 1 ,    UpperCamelCase__ = True ,    UpperCamelCase__ = 1 / 255 ,    UpperCamelCase__ = True ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    **UpperCamelCase__ ,    ):
						super().__init__(**UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Any													=   size if size is not None else {'height': 384, 'width': 384}
						SCREAMING_SNAKE_CASE_   :	str													=   get_size_dict(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	str													=   do_resize
						SCREAMING_SNAKE_CASE_   :	str													=   size
						SCREAMING_SNAKE_CASE_   :	int													=   keep_aspect_ratio
						SCREAMING_SNAKE_CASE_   :	Tuple													=   ensure_multiple_of
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   resample
						SCREAMING_SNAKE_CASE_   :	int													=   do_rescale
						SCREAMING_SNAKE_CASE_   :	int													=   rescale_factor
						SCREAMING_SNAKE_CASE_   :	str													=   do_normalize
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
						SCREAMING_SNAKE_CASE_   :	int													=   image_std if image_std is not None else IMAGENET_STANDARD_STD


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = False ,    UpperCamelCase__ = 1 ,    UpperCamelCase__ = PILImageResampling.BICUBIC ,    UpperCamelCase__ = None ,    **UpperCamelCase__ ,    ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   get_size_dict(UpperCamelCase__       )
						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()}'''       )
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   get_resize_output_image_size(
						    UpperCamelCase__ ,    output_size=(size['height'], size['width']) ,    keep_aspect_ratio=UpperCamelCase__ ,    multiple=UpperCamelCase__ ,    )
						return resize(UpperCamelCase__ ,    size=UpperCamelCase__ ,    resample=UpperCamelCase__ ,    data_format=UpperCamelCase__ ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = None ,    **UpperCamelCase__ ,    ):
						return rescale(UpperCamelCase__ ,    scale=UpperCamelCase__ ,    data_format=UpperCamelCase__ ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = None ,    **UpperCamelCase__ ,    ):
						return normalize(UpperCamelCase__ ,    mean=UpperCamelCase__ ,    std=UpperCamelCase__ ,    data_format=UpperCamelCase__ ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = ChannelDimension.FIRST ,    **UpperCamelCase__ ,    ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   do_resize if do_resize is not None else self.do_resize
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   size if size is not None else self.size
						SCREAMING_SNAKE_CASE_   :	str													=   get_size_dict(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   keep_aspect_ratio if keep_aspect_ratio is not None else self.keep_aspect_ratio
						SCREAMING_SNAKE_CASE_   :	str													=   ensure_multiple_of if ensure_multiple_of is not None else self.ensure_multiple_of
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   resample if resample is not None else self.resample
						SCREAMING_SNAKE_CASE_   :	Dict													=   do_rescale if do_rescale is not None else self.do_rescale
						SCREAMING_SNAKE_CASE_   :	Dict													=   rescale_factor if rescale_factor is not None else self.rescale_factor
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   do_normalize if do_normalize is not None else self.do_normalize
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   image_mean if image_mean is not None else self.image_mean
						SCREAMING_SNAKE_CASE_   :	Dict													=   image_std if image_std is not None else self.image_std

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   make_list_of_images(UpperCamelCase__       )

						if not valid_images(UpperCamelCase__       ):
										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 or resample is None:
										raise ValueError('Size and resample 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_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.
						SCREAMING_SNAKE_CASE_   :	Any													=   [to_numpy_array(UpperCamelCase__       ) for image in images]

						if do_resize:
										SCREAMING_SNAKE_CASE_   :	Tuple													=   [self.resize(image=UpperCamelCase__ ,    size=UpperCamelCase__ ,    resample=UpperCamelCase__       ) for image in images]

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

						if do_normalize:
										SCREAMING_SNAKE_CASE_   :	Any													=   [self.normalize(image=UpperCamelCase__ ,    mean=UpperCamelCase__ ,    std=UpperCamelCase__       ) for image in images]

						SCREAMING_SNAKE_CASE_   :	str													=   [to_channel_dimension_format(UpperCamelCase__ ,    UpperCamelCase__       ) for image in images]

						SCREAMING_SNAKE_CASE_   :	Dict													=   {'pixel_values': images}
						return BatchFeature(data=UpperCamelCase__ ,    tensor_type=UpperCamelCase__       )






		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ = None       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   outputs.logits

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

										if is_torch_tensor(UpperCamelCase__       ):
														SCREAMING_SNAKE_CASE_   :	int													=   target_sizes.numpy()

										SCREAMING_SNAKE_CASE_   :	Tuple													=   []

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

						return semantic_segmentation