


'''simple docstring'''
import unittest

from transformers import AutoTokenizer, NystromformerConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
		import torch

		from transformers import (
		    NystromformerForMaskedLM,
		    NystromformerForMultipleChoice,
		    NystromformerForQuestionAnswering,
		    NystromformerForSequenceClassification,
		    NystromformerForTokenClassification,
		    NystromformerModel,
		)
		from transformers.models.nystromformer.modeling_nystromformer import NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST
class      lowercase			:

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_=13					,     UpperCamelCase_=7					,     UpperCamelCase_=True					,     UpperCamelCase_=True					,     UpperCamelCase_=True					,     UpperCamelCase_=True					,     UpperCamelCase_=99					,     UpperCamelCase_=32					,     UpperCamelCase_=5					,     UpperCamelCase_=4					,     UpperCamelCase_=37					,     UpperCamelCase_="gelu"					,     UpperCamelCase_=0.1					,     UpperCamelCase_=0.1					,     UpperCamelCase_=512					,     UpperCamelCase_=16					,     UpperCamelCase_=2					,     UpperCamelCase_=0.02					,     UpperCamelCase_=3					,     UpperCamelCase_=4					,     UpperCamelCase_=None					,     ):

			'''simple docstring'''


			UpperCamelCase__     :Dict							      =				parent
			UpperCamelCase__     :List[Any]							      =				batch_size
			UpperCamelCase__     :List[str]							      =				seq_length
			UpperCamelCase__     :Dict							      =				is_training
			UpperCamelCase__     :Any							      =				use_input_mask
			UpperCamelCase__     :int							      =				use_token_type_ids
			UpperCamelCase__     :Tuple							      =				use_labels
			UpperCamelCase__     :List[Any]							      =				vocab_size
			UpperCamelCase__     :int							      =				hidden_size
			UpperCamelCase__     :Dict							      =				num_hidden_layers
			UpperCamelCase__     :List[Any]							      =				num_attention_heads
			UpperCamelCase__     :Dict							      =				intermediate_size
			UpperCamelCase__     :str							      =				hidden_act
			UpperCamelCase__     :Tuple							      =				hidden_dropout_prob
			UpperCamelCase__     :Optional[int]							      =				attention_probs_dropout_prob
			UpperCamelCase__     :Optional[int]							      =				max_position_embeddings
			UpperCamelCase__     :Tuple							      =				type_vocab_size
			UpperCamelCase__     :Optional[Any]							      =				type_sequence_label_size
			UpperCamelCase__     :int							      =				initializer_range
			UpperCamelCase__     :List[Any]							      =				num_labels
			UpperCamelCase__     :List[Any]							      =				num_choices
			UpperCamelCase__     :Dict							      =				scope




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :Dict							      =				ids_tensor([self.batch_size, self.seq_length]					,     self.vocab_size							)

			UpperCamelCase__     :Union[str, Any]							      =				None
			if self.use_input_mask:
				UpperCamelCase__     :Any							      =				random_attention_mask([self.batch_size, self.seq_length]							)

			UpperCamelCase__     :Dict							      =				None
			if self.use_token_type_ids:
				UpperCamelCase__     :List[Any]							      =				ids_tensor([self.batch_size, self.seq_length]					,     self.type_vocab_size							)

			UpperCamelCase__     :List[str]							      =				None
			UpperCamelCase__     :Union[str, Any]							      =				None
			UpperCamelCase__     :Union[str, Any]							      =				None
			if self.use_labels:
				UpperCamelCase__     :Tuple							      =				ids_tensor([self.batch_size]					,     self.type_sequence_label_size							)
				UpperCamelCase__     :str							      =				ids_tensor([self.batch_size, self.seq_length]					,     self.num_labels							)
				UpperCamelCase__     :int							      =				ids_tensor([self.batch_size]					,     self.num_choices							)

			UpperCamelCase__     :Optional[Any]							      =				self.get_config()

			return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			return NystromformerConfig(
			    vocab_size=self.vocab_size					,     hidden_size=self.hidden_size					,     num_hidden_layers=self.num_hidden_layers					,     num_attention_heads=self.num_attention_heads					,     intermediate_size=self.intermediate_size					,     hidden_act=self.hidden_act					,     hidden_dropout_prob=self.hidden_dropout_prob					,     attention_probs_dropout_prob=self.attention_probs_dropout_prob					,     max_position_embeddings=self.max_position_embeddings					,     type_vocab_size=self.type_vocab_size					,     is_decoder=A__					,     initializer_range=self.initializer_range					,     )




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

			'''simple docstring'''


			UpperCamelCase__     :Union[str, Any]							      =				NystromformerModel(config=A__							)
			model.to(A__							)
			model.eval()
			UpperCamelCase__     :Optional[int]							      =				model(A__					,     attention_mask=A__					,     token_type_ids=A__							)
			UpperCamelCase__     :Union[str, Any]							      =				model(A__					,     token_type_ids=A__							)
			UpperCamelCase__     :str							      =				model(A__							)
			self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, self.seq_length, self.hidden_size)							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

			'''simple docstring'''


			UpperCamelCase__     :Tuple							      =				NystromformerForMaskedLM(config=A__							)
			model.to(A__							)
			model.eval()
			UpperCamelCase__     :Any							      =				model(A__					,     attention_mask=A__					,     token_type_ids=A__					,     labels=A__							)
			self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.seq_length, self.vocab_size)							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

			'''simple docstring'''


			UpperCamelCase__     :List[str]							      =				NystromformerForQuestionAnswering(config=A__							)
			model.to(A__							)
			model.eval()
			UpperCamelCase__     :Optional[Any]							      =				model(
			    A__					,     attention_mask=A__					,     token_type_ids=A__					,     start_positions=A__					,     end_positions=A__					,     )
			self.parent.assertEqual(result.start_logits.shape					,     (self.batch_size, self.seq_length)							)
			self.parent.assertEqual(result.end_logits.shape					,     (self.batch_size, self.seq_length)							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

			'''simple docstring'''


			UpperCamelCase__     :Union[str, Any]							      =				self.num_labels
			UpperCamelCase__     :List[Any]							      =				NystromformerForSequenceClassification(A__							)
			model.to(A__							)
			model.eval()
			UpperCamelCase__     :Dict							      =				model(A__					,     attention_mask=A__					,     token_type_ids=A__					,     labels=A__							)
			self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.num_labels)							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

			'''simple docstring'''


			UpperCamelCase__     :Union[str, Any]							      =				self.num_labels
			UpperCamelCase__     :Any							      =				NystromformerForTokenClassification(config=A__							)
			model.to(A__							)
			model.eval()
			UpperCamelCase__     :Optional[Any]							      =				model(A__					,     attention_mask=A__					,     token_type_ids=A__					,     labels=A__							)
			self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.seq_length, self.num_labels)							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

			'''simple docstring'''


			UpperCamelCase__     :int							      =				self.num_choices
			UpperCamelCase__     :str							      =				NystromformerForMultipleChoice(config=A__							)
			model.to(A__							)
			model.eval()
			UpperCamelCase__     :int							      =				input_ids.unsqueeze(1							).expand(-1					,     self.num_choices					,     -1							).contiguous()
			UpperCamelCase__     :List[str]							      =				token_type_ids.unsqueeze(1							).expand(-1					,     self.num_choices					,     -1							).contiguous()
			UpperCamelCase__     :Dict							      =				input_mask.unsqueeze(1							).expand(-1					,     self.num_choices					,     -1							).contiguous()
			UpperCamelCase__     :Any							      =				model(
			    A__					,     attention_mask=A__					,     token_type_ids=A__					,     labels=A__					,     )
			self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.num_choices)							)




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :Tuple							      =				self.prepare_config_and_inputs()
			(
			    (
			    UpperCamelCase__		
			)      ,       (
			    UpperCamelCase__		
			)      ,       (
			    UpperCamelCase__		
			)      ,       (
			    UpperCamelCase__		
			)      ,       (
			    UpperCamelCase__		
			)      ,       (
			    UpperCamelCase__		
			)      ,       (
			    UpperCamelCase__		
			)      ,       		
			)     :Tuple							      =				config_and_inputs
			UpperCamelCase__     :Optional[int]							      =				{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
			return config, inputs_dict



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

		"""simple docstring"""

		_a									=       (
		    (
		        NystromformerModel,
		        NystromformerForMaskedLM,
		        NystromformerForMultipleChoice,
		        NystromformerForQuestionAnswering,
		        NystromformerForSequenceClassification,
		        NystromformerForTokenClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		_a									=       (
		    {
		        'feature-extraction': NystromformerModel,
		        'fill-mask': NystromformerForMaskedLM,
		        'question-answering': NystromformerForQuestionAnswering,
		        'text-classification': NystromformerForSequenceClassification,
		        'token-classification': NystromformerForTokenClassification,
		        'zero-shot': NystromformerForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		_a									=       False
		_a									=       False




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :Union[str, Any]							      =				NystromformerModelTester(self							)
			UpperCamelCase__     :Optional[Any]							      =				ConfigTester(self					,     config_class=A__					,     hidden_size=37							)




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			self.config_tester.run_common_tests()




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :str							      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*A__							)




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :List[str]							      =				self.model_tester.prepare_config_and_inputs()
			for type in ["absolute", "relative_key", "relative_key_query"]:
				UpperCamelCase__     :Dict							      =				type
				self.model_tester.create_and_check_model(*A__							)




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :Tuple							      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_masked_lm(*A__							)




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :List[str]							      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_multiple_choice(*A__							)




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :Dict							      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_question_answering(*A__							)




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :List[str]							      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_sequence_classification(*A__							)




		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :Any							      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_token_classification(*A__							)




		@slow
		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			for model_name in NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				UpperCamelCase__     :Union[str, Any]							      =				NystromformerModel.from_pretrained(A__							)
				self.assertIsNotNone(A__							)



@require_torch
class      lowercase			(							unittest.TestCase      ):

		"""simple docstring"""

		@slow
		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :Dict							      =				NystromformerModel.from_pretrained('''uw-madison/nystromformer-512'''							)
			UpperCamelCase__     :List[str]							      =				torch.tensor([[0, 1, 2, 3, 4, 5]]							)

			with torch.no_grad():
				UpperCamelCase__     :Dict							      =				model(A__							)[0]

			UpperCamelCase__     :List[Any]							      =				torch.Size((1, 6, 768)							)
			self.assertEqual(output.shape					,     A__							)

			UpperCamelCase__     :Optional[Any]							      =				torch.tensor(
			    [[[-0.4532, -0.0936, 0.5137], [-0.2676, 0.0628, 0.6186], [-0.3629, -0.1726, 0.4716]]]							)

			self.assertTrue(torch.allclose(output[:, :3, :3]					,     A__					,     atol=1e-4							)							)




		@slow
		def 					lowerCAmelCase__       (	self							):

			'''simple docstring'''


			UpperCamelCase__     :List[str]							      =				'''the [MASK] of Belgium is Brussels'''

			UpperCamelCase__     :Optional[int]							      =				AutoTokenizer.from_pretrained('''uw-madison/nystromformer-512'''							)
			UpperCamelCase__     :Optional[Any]							      =				NystromformerForMaskedLM.from_pretrained('''uw-madison/nystromformer-512'''							)

			UpperCamelCase__     :List[str]							      =				tokenizer(A__					,     return_tensors='''pt'''							)

			with torch.no_grad():
				UpperCamelCase__     :List[Any]							      =				model(encoding.input_ids							).logits

			UpperCamelCase__     :List[str]							      =				token_logits[:, 2, :].argmax(-1							)[0]

			self.assertEqual(tokenizer.decode(A__							)					,     '''capital'''							)



'''simple docstring'''
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


__snake_case							   =  logging.get_logger(__name__)


def     a   (    __a				,      __a				,      __a				,      __a     )						->			Tuple[int, int]:



					'''simple docstring'''






					def constraint_to_multiple_of(__a				,      __a				,      __a=0				,      __a=None     ):
										UpperCamelCase__     :Union[str, Any]							      =				round(val / multiple     ) * multiple

										if max_val is not None and x > max_val:
															UpperCamelCase__     :List[str]							      =				math.floor(val / multiple     ) * multiple

										if x < min_val:
															UpperCamelCase__     :Union[str, Any]							      =				math.ceil(val / multiple     ) * multiple

										return x

					UpperCamelCase__     :str							      =				(output_size, output_size) if isinstance(__a				,      __a     ) else output_size

					UpperCamelCase__      ,       UpperCamelCase__     :int							      =				get_image_size(__a     )
					UpperCamelCase__      ,       UpperCamelCase__     :Optional[int]							      =				output_size

					# determine new height and width
					UpperCamelCase__     :List[str]							      =				output_height / input_height
					UpperCamelCase__     :str							      =				output_width / input_width

					if keep_aspect_ratio:
										# scale as little as possible
										if abs(1 - scale_width     ) < abs(1 - scale_height     ):
															# fit width
															UpperCamelCase__     :str							      =				scale_width
										else:
															# fit height
															UpperCamelCase__     :int							      =				scale_height

					UpperCamelCase__     :Optional[int]							      =				constraint_to_multiple_of(scale_height * input_height				,      multiple=__a     )
					UpperCamelCase__     :List[Any]							      =				constraint_to_multiple_of(scale_width * input_width				,      multiple=__a     )

					return (new_height, new_width)







class      lowercase			(							A__      ):

		"""simple docstring"""

		_a									=       ['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_					,     ):

							'''simple docstring'''


							super().__init__(**UpperCamelCase_							)
							UpperCamelCase__     :List[Any]							      =				size if size is not None else {'''height''': 384, '''width''': 384}
							UpperCamelCase__     :Dict							      =				get_size_dict(UpperCamelCase_							)
							UpperCamelCase__     :Dict							      =				do_resize
							UpperCamelCase__     :Union[str, Any]							      =				size
							UpperCamelCase__     :List[Any]							      =				keep_aspect_ratio
							UpperCamelCase__     :Optional[int]							      =				ensure_multiple_of
							UpperCamelCase__     :Union[str, Any]							      =				resample
							UpperCamelCase__     :str							      =				do_rescale
							UpperCamelCase__     :Union[str, Any]							      =				rescale_factor
							UpperCamelCase__     :List[str]							      =				do_normalize
							UpperCamelCase__     :List[str]							      =				image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
							UpperCamelCase__     :Dict							      =				image_std if image_std is not None else IMAGENET_STANDARD_STD




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = False					,     UpperCamelCase_ = 1					,     UpperCamelCase_ = PILImageResampling.BICUBIC					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :int							      =				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()}'''							)
							UpperCamelCase__     :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 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


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




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							return normalize(UpperCamelCase_					,     mean=UpperCamelCase_					,     std=UpperCamelCase_					,     data_format=UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	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_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				do_resize if do_resize is not None else self.do_resize
							UpperCamelCase__     :Any							      =				size if size is not None else self.size
							UpperCamelCase__     :List[str]							      =				get_size_dict(UpperCamelCase_							)
							UpperCamelCase__     :Any							      =				keep_aspect_ratio if keep_aspect_ratio is not None else self.keep_aspect_ratio
							UpperCamelCase__     :str							      =				ensure_multiple_of if ensure_multiple_of is not None else self.ensure_multiple_of
							UpperCamelCase__     :Union[str, Any]							      =				resample if resample is not None else self.resample
							UpperCamelCase__     :str							      =				do_rescale if do_rescale is not None else self.do_rescale
							UpperCamelCase__     :int							      =				rescale_factor if rescale_factor is not None else self.rescale_factor
							UpperCamelCase__     :Optional[Any]							      =				do_normalize if do_normalize is not None else self.do_normalize
							UpperCamelCase__     :Optional[int]							      =				image_mean if image_mean is not None else self.image_mean
							UpperCamelCase__     :List[str]							      =				image_std if image_std is not None else self.image_std

							UpperCamelCase__     :List[str]							      =				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.
							UpperCamelCase__     :str							      =				[to_numpy_array(UpperCamelCase_							) for image in images]

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

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

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

							UpperCamelCase__     :Optional[int]							      =				[to_channel_dimension_format(UpperCamelCase_					,     UpperCamelCase_							) for image in images]

							UpperCamelCase__     :List[str]							      =				{'''pixel_values''': images}
							return BatchFeature(data=UpperCamelCase_					,     tensor_type=UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_ = None							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				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_							):
																	UpperCamelCase__     :Union[str, Any]							      =				target_sizes.numpy()

												UpperCamelCase__     :int							      =				[]

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

							return semantic_segmentation