


import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
		import torch

		from transformers import (
		    DebertaForMaskedLM,
		    DebertaForQuestionAnswering,
		    DebertaForSequenceClassification,
		    DebertaForTokenClassification,
		    DebertaModel,
		)
		from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST




class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	def __init__(			self      :    Optional[Any]      ,      UpperCAmelCase__      :    Optional[int]      ,      UpperCAmelCase__      :    Any=1_3      ,      UpperCAmelCase__      :    Dict=7      ,      UpperCAmelCase__      :    List[Any]=True      ,      UpperCAmelCase__      :    Union[str, Any]=True      ,      UpperCAmelCase__      :    Union[str, Any]=True      ,      UpperCAmelCase__      :    Optional[Any]=True      ,      UpperCAmelCase__      :    Union[str, Any]=9_9      ,      UpperCAmelCase__      :    Optional[int]=3_2      ,      UpperCAmelCase__      :    List[Any]=5      ,      UpperCAmelCase__      :    List[str]=4      ,      UpperCAmelCase__      :    Optional[int]=3_7      ,      UpperCAmelCase__      :    Union[str, Any]="gelu"      ,      UpperCAmelCase__      :    str=0.1      ,      UpperCAmelCase__      :    List[str]=0.1      ,      UpperCAmelCase__      :    str=5_1_2      ,      UpperCAmelCase__      :    Optional[Any]=1_6      ,      UpperCAmelCase__      :    Union[str, Any]=2      ,      UpperCAmelCase__      :    Tuple=0.02      ,      UpperCAmelCase__      :    Union[str, Any]=False      ,      UpperCAmelCase__      :    Any=True      ,      UpperCAmelCase__      :    List[str]="None"      ,      UpperCAmelCase__      :    int=3      ,      UpperCAmelCase__      :    Union[str, Any]=4      ,      UpperCAmelCase__      :    str=None      ,      )	->     Optional[Any]:
						__SCREAMING_SNAKE_CASE						       =    parent
						__SCREAMING_SNAKE_CASE						       =    batch_size
						__SCREAMING_SNAKE_CASE						       =    seq_length
						__SCREAMING_SNAKE_CASE						       =    is_training
						__SCREAMING_SNAKE_CASE						       =    use_input_mask
						__SCREAMING_SNAKE_CASE						       =    use_token_type_ids
						__SCREAMING_SNAKE_CASE						       =    use_labels
						__SCREAMING_SNAKE_CASE						       =    vocab_size
						__SCREAMING_SNAKE_CASE						       =    hidden_size
						__SCREAMING_SNAKE_CASE						       =    num_hidden_layers
						__SCREAMING_SNAKE_CASE						       =    num_attention_heads
						__SCREAMING_SNAKE_CASE						       =    intermediate_size
						__SCREAMING_SNAKE_CASE						       =    hidden_act
						__SCREAMING_SNAKE_CASE						       =    hidden_dropout_prob
						__SCREAMING_SNAKE_CASE						       =    attention_probs_dropout_prob
						__SCREAMING_SNAKE_CASE						       =    max_position_embeddings
						__SCREAMING_SNAKE_CASE						       =    type_vocab_size
						__SCREAMING_SNAKE_CASE						       =    type_sequence_label_size
						__SCREAMING_SNAKE_CASE						       =    initializer_range
						__SCREAMING_SNAKE_CASE						       =    num_labels
						__SCREAMING_SNAKE_CASE						       =    num_choices
						__SCREAMING_SNAKE_CASE						       =    relative_attention
						__SCREAMING_SNAKE_CASE						       =    position_biased_input
						__SCREAMING_SNAKE_CASE						       =    pos_att_type
						__SCREAMING_SNAKE_CASE						       =    scope




	def   UpperCAmelCase_				(			self      :    Any       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    ids_tensor([self.batch_size, self.seq_length]      ,      self.vocab_size       )

						__SCREAMING_SNAKE_CASE						       =    None
						if self.use_input_mask:
											__SCREAMING_SNAKE_CASE						       =    ids_tensor([self.batch_size, self.seq_length]      ,      vocab_size=2       )

						__SCREAMING_SNAKE_CASE						       =    None
						if self.use_token_type_ids:
											__SCREAMING_SNAKE_CASE						       =    ids_tensor([self.batch_size, self.seq_length]      ,      self.type_vocab_size       )

						__SCREAMING_SNAKE_CASE						       =    None
						__SCREAMING_SNAKE_CASE						       =    None
						__SCREAMING_SNAKE_CASE						       =    None
						if self.use_labels:
											__SCREAMING_SNAKE_CASE						       =    ids_tensor([self.batch_size]      ,      self.type_sequence_label_size       )
											__SCREAMING_SNAKE_CASE						       =    ids_tensor([self.batch_size, self.seq_length]      ,      self.num_labels       )
											__SCREAMING_SNAKE_CASE						       =    ids_tensor([self.batch_size]      ,      self.num_choices       )

						__SCREAMING_SNAKE_CASE						       =    self.get_config()

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




	def   UpperCAmelCase_				(			self      :    int       )	->     Optional[Any]:
						return DebertaConfig(
						    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      ,      initializer_range=self.initializer_range      ,      relative_attention=self.relative_attention      ,      position_biased_input=self.position_biased_input      ,      pos_att_type=self.pos_att_type      ,      )




	def   UpperCAmelCase_				(			self      :    Dict       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    self.get_config()
						__SCREAMING_SNAKE_CASE						       =    3_0_0
						return config




	def   UpperCAmelCase_				(			self      :    Any      ,      UpperCAmelCase__      :    Tuple       )	->     Optional[Any]:
						self.parent.assertListEqual(list(result.loss.size()       )      ,      []       )




	def   UpperCAmelCase_				(			self      :    Union[str, Any]      ,      UpperCAmelCase__      :    Optional[Any]      ,      UpperCAmelCase__      :    Union[str, Any]      ,      UpperCAmelCase__      :    Optional[Any]      ,      UpperCAmelCase__      :    Any      ,      UpperCAmelCase__      :    List[str]      ,      UpperCAmelCase__      :    List[str]      ,      UpperCAmelCase__      :    Union[str, Any]       )	->     str:
						__SCREAMING_SNAKE_CASE						       =    DebertaModel(config=UpperCAmelCase__       )
						model.to(UpperCAmelCase__       )
						model.eval()
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__      ,      attention_mask=UpperCAmelCase__      ,      token_type_ids=UpperCAmelCase__       )[0]
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__      ,      token_type_ids=UpperCAmelCase__       )[0]
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__       )[0]

						self.parent.assertListEqual(list(sequence_output.size()       )      ,      [self.batch_size, self.seq_length, self.hidden_size]       )




	def   UpperCAmelCase_				(			self      :    Tuple      ,      UpperCAmelCase__      :    Tuple      ,      UpperCAmelCase__      :    str      ,      UpperCAmelCase__      :    Any      ,      UpperCAmelCase__      :    Any      ,      UpperCAmelCase__      :    Optional[int]      ,      UpperCAmelCase__      :    Union[str, Any]      ,      UpperCAmelCase__      :    Union[str, Any]       )	->     str:
						__SCREAMING_SNAKE_CASE						       =    DebertaForMaskedLM(config=UpperCAmelCase__       )
						model.to(UpperCAmelCase__       )
						model.eval()
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__      ,      attention_mask=UpperCAmelCase__      ,      token_type_ids=UpperCAmelCase__      ,      labels=UpperCAmelCase__       )

						self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.seq_length, self.vocab_size)       )




	def   UpperCAmelCase_				(			self      :    Union[str, Any]      ,      UpperCAmelCase__      :    List[str]      ,      UpperCAmelCase__      :    Optional[int]      ,      UpperCAmelCase__      :    int      ,      UpperCAmelCase__      :    Optional[Any]      ,      UpperCAmelCase__      :    Optional[Any]      ,      UpperCAmelCase__      :    Optional[int]      ,      UpperCAmelCase__      :    Union[str, Any]       )	->     Dict:
						__SCREAMING_SNAKE_CASE						       =    self.num_labels
						__SCREAMING_SNAKE_CASE						       =    DebertaForSequenceClassification(UpperCAmelCase__       )
						model.to(UpperCAmelCase__       )
						model.eval()
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__      ,      attention_mask=UpperCAmelCase__      ,      token_type_ids=UpperCAmelCase__      ,      labels=UpperCAmelCase__       )
						self.parent.assertListEqual(list(result.logits.size()       )      ,      [self.batch_size, self.num_labels]       )
						self.check_loss_output(UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Tuple      ,      UpperCAmelCase__      :    Optional[int]      ,      UpperCAmelCase__      :    str      ,      UpperCAmelCase__      :    int      ,      UpperCAmelCase__      :    str      ,      UpperCAmelCase__      :    List[str]      ,      UpperCAmelCase__      :    int      ,      UpperCAmelCase__      :    Optional[Any]       )	->     List[str]:
						__SCREAMING_SNAKE_CASE						       =    self.num_labels
						__SCREAMING_SNAKE_CASE						       =    DebertaForTokenClassification(config=UpperCAmelCase__       )
						model.to(UpperCAmelCase__       )
						model.eval()
						__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__      ,      attention_mask=UpperCAmelCase__      ,      token_type_ids=UpperCAmelCase__      ,      labels=UpperCAmelCase__       )
						self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.seq_length, self.num_labels)       )




	def   UpperCAmelCase_				(			self      :    Tuple      ,      UpperCAmelCase__      :    Union[str, Any]      ,      UpperCAmelCase__      :    int      ,      UpperCAmelCase__      :    str      ,      UpperCAmelCase__      :    Optional[Any]      ,      UpperCAmelCase__      :    str      ,      UpperCAmelCase__      :    List[str]      ,      UpperCAmelCase__      :    int       )	->     Union[str, Any]:
						__SCREAMING_SNAKE_CASE						       =    DebertaForQuestionAnswering(config=UpperCAmelCase__       )
						model.to(UpperCAmelCase__       )
						model.eval()
						__SCREAMING_SNAKE_CASE						       =    model(
						    UpperCAmelCase__      ,      attention_mask=UpperCAmelCase__      ,      token_type_ids=UpperCAmelCase__      ,      start_positions=UpperCAmelCase__      ,      end_positions=UpperCAmelCase__      ,      )
						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   UpperCAmelCase_				(			self      :    List[Any]       )	->     Union[str, Any]:
						__SCREAMING_SNAKE_CASE						       =    self.prepare_config_and_inputs()
						(
						    (
						    __SCREAMING_SNAKE_CASE  
						)       ,  (
						    __SCREAMING_SNAKE_CASE  
						)       ,  (
						    __SCREAMING_SNAKE_CASE  
						)       ,  (
						    __SCREAMING_SNAKE_CASE  
						)       ,  (
						    __SCREAMING_SNAKE_CASE  
						)       ,  (
						    __SCREAMING_SNAKE_CASE  
						)       ,  (
						    __SCREAMING_SNAKE_CASE  
						)       ,    
						)						       =    config_and_inputs
						__SCREAMING_SNAKE_CASE						       =    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
						return config, inputs_dict




@require_torch
class 			UpperCamelCase_     (			UpperCamelCase      ,  UpperCamelCase      ,  unittest.TestCase):

	"""simple docstring"""





	snake_case__    :  Tuple    =      (
	    (
	        DebertaModel,
	        DebertaForMaskedLM,
	        DebertaForSequenceClassification,
	        DebertaForTokenClassification,
	        DebertaForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	snake_case__    :  Union[str, Any]    =      (
	    {
	        "feature-extraction": DebertaModel,
	        "fill-mask": DebertaForMaskedLM,
	        "question-answering": DebertaForQuestionAnswering,
	        "text-classification": DebertaForSequenceClassification,
	        "token-classification": DebertaForTokenClassification,
	        "zero-shot": DebertaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	snake_case__    :  List[Any]    =      True
	snake_case__    :  List[str]    =      False
	snake_case__    :  str    =      False
	snake_case__    :  List[Any]    =      False
	snake_case__    :  Tuple    =      False




	def   UpperCAmelCase_				(			self      :    Tuple       )	->     Union[str, Any]:
						__SCREAMING_SNAKE_CASE						       =    DebertaModelTester(self       )
						__SCREAMING_SNAKE_CASE						       =    ConfigTester(self      ,      config_class=UpperCAmelCase__      ,      hidden_size=3_7       )




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     int:
						self.config_tester.run_common_tests()




	def   UpperCAmelCase_				(			self      :    Tuple       )	->     Union[str, Any]:
						__SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_model(*UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    str       )	->     Union[str, Any]:
						__SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_sequence_classification(*UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Any       )	->     str:
						__SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_masked_lm(*UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     List[str]:
						__SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_question_answering(*UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    int       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_token_classification(*UpperCAmelCase__       )




	@slow
	def   UpperCAmelCase_				(			self      :    List[Any]       )	->     Optional[Any]:
						for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__SCREAMING_SNAKE_CASE						       =    DebertaModel.from_pretrained(UpperCAmelCase__       )
											self.assertIsNotNone(UpperCAmelCase__       )




@require_torch
@require_sentencepiece
@require_tokenizers
class 			UpperCamelCase_     (			unittest.TestCase):

	"""simple docstring"""





	@unittest.skip(reason="Model not available yet"       )
	def   UpperCAmelCase_				(			self      :    int       )	->     Dict:
						pass




	@slow
	def   UpperCAmelCase_				(			self      :    Optional[int]       )	->     List[Any]:
						__SCREAMING_SNAKE_CASE						       =    DebertaModel.from_pretrained("microsoft/deberta-base"       )

						__SCREAMING_SNAKE_CASE						       =    torch.tensor([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]       )
						__SCREAMING_SNAKE_CASE						       =    torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
						with torch.no_grad():
											__SCREAMING_SNAKE_CASE						       =    model(UpperCAmelCase__      ,      attention_mask=UpperCAmelCase__       )[0]
						# compare the actual values for a slice.
						__SCREAMING_SNAKE_CASE						       =    torch.tensor(
						    [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]]       )
						self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,      UpperCAmelCase__      ,      atol=1E-4       )      ,      F"""{output[:, 1:4, 1:4]}"""       )




"""simple docstring"""







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


a__    :							Optional[int]            =					logging.get_logger(__name__)




class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	snake_case__    :  Optional[Any]    =      ["pixel_values"]




	def __init__(			self      :    Dict      ,      UpperCAmelCase__      :    bool = True      ,      UpperCAmelCase__      :    Dict[str, int] = None      ,      UpperCAmelCase__      :    PILImageResampling = PILImageResampling.BILINEAR      ,      UpperCAmelCase__      :    bool = True      ,      UpperCAmelCase__      :    Union[int, float] = 1 / 2_5_5      ,      UpperCAmelCase__      :    bool = True      ,      UpperCAmelCase__      :    Dict[str, int] = None      ,      UpperCAmelCase__      :    bool = True      ,      **UpperCAmelCase__      :    Dict      ,      )	->     None:
						super().__init__(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    size if size is not None else {"shortest_edge": 2_2_4}
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      default_to_square=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    crop_size if crop_size is not None else {"height": 2_5_6, "width": 2_5_6}
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      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   UpperCAmelCase_				(			self      :    Any      ,      UpperCAmelCase__      :    np.ndarray      ,      UpperCAmelCase__      :    Dict[str, int]      ,      UpperCAmelCase__      :    PILImageResampling = PIL.Image.BILINEAR      ,      UpperCAmelCase__      :    Optional[Union[str, ChannelDimension]] = None      ,      **UpperCAmelCase__      :    Optional[Any]      ,      )	->     np.ndarray:
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      default_to_square=UpperCAmelCase__       )
						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(UpperCAmelCase__      ,      size=size["shortest_edge"]      ,      default_to_square=UpperCAmelCase__       )
						return resize(UpperCAmelCase__      ,      size=UpperCAmelCase__      ,      resample=UpperCAmelCase__      ,      data_format=UpperCAmelCase__      ,      **UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    str      ,      UpperCAmelCase__      :    np.ndarray      ,      UpperCAmelCase__      :    Dict[str, int]      ,      UpperCAmelCase__      :    Optional[Union[str, ChannelDimension]] = None      ,      **UpperCAmelCase__      :    Any      ,      )	->     np.ndarray:
						__SCREAMING_SNAKE_CASE						       =    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()}"""       )
						return center_crop(UpperCAmelCase__      ,      size=(size["height"], size["width"])      ,      data_format=UpperCAmelCase__      ,      **UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    np.ndarray      ,      UpperCAmelCase__      :    Union[int, float]      ,      UpperCAmelCase__      :    Optional[Union[str, ChannelDimension]] = None      ,      **UpperCAmelCase__      :    Dict      ,      )	->     Dict:
						return rescale(UpperCAmelCase__      ,      scale=UpperCAmelCase__      ,      data_format=UpperCAmelCase__      ,      **UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    np.ndarray      ,      UpperCAmelCase__      :    Optional[Union[str, ChannelDimension]] = None       )	->     np.ndarray:
						return flip_channel_order(UpperCAmelCase__      ,      data_format=UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    ImageInput      ,      UpperCAmelCase__      :    bool = None      ,      UpperCAmelCase__      :    Dict[str, int] = None      ,      UpperCAmelCase__      :    PILImageResampling = None      ,      UpperCAmelCase__      :    bool = None      ,      UpperCAmelCase__      :    float = None      ,      UpperCAmelCase__      :    bool = None      ,      UpperCAmelCase__      :    Dict[str, int] = None      ,      UpperCAmelCase__      :    bool = None      ,      UpperCAmelCase__      :    Optional[Union[str, TensorType]] = None      ,      UpperCAmelCase__      :    ChannelDimension = ChannelDimension.FIRST      ,      **UpperCAmelCase__      :    str      ,      )	->     PIL.Image.Image:
						__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(UpperCAmelCase__      ,      default_to_square=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    crop_size if crop_size is not None else self.crop_size
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      param_name="crop_size"       )

						__SCREAMING_SNAKE_CASE						       =    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:
											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(UpperCAmelCase__       ) for image in images]

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

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

						if do_rescale:
											__SCREAMING_SNAKE_CASE						       =    [self.rescale(image=UpperCAmelCase__      ,      scale=UpperCAmelCase__       ) 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=UpperCAmelCase__       ) for image in images]

						__SCREAMING_SNAKE_CASE						       =    [to_channel_dimension_format(UpperCAmelCase__      ,      UpperCAmelCase__       ) for image in images]

						__SCREAMING_SNAKE_CASE						       =    {"pixel_values": images}
						return BatchFeature(data=UpperCAmelCase__      ,      tensor_type=UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[Any]      ,      UpperCAmelCase__      :    List[Any]      ,      UpperCAmelCase__      :    List[Tuple] = None       )	->     Optional[int]:
						__SCREAMING_SNAKE_CASE						       =    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						       =    target_sizes.numpy()

											__SCREAMING_SNAKE_CASE						       =    []

											for idx in range(len(UpperCAmelCase__       )       ):
																__SCREAMING_SNAKE_CASE						       =    torch.nn.functional.interpolate(
																    logits[idx].unsqueeze(dim=0       )      ,      size=target_sizes[idx]      ,      mode="bilinear"      ,      align_corners=UpperCAmelCase__       )
																__SCREAMING_SNAKE_CASE						       =    resized_logits[0].argmax(dim=0       )
																semantic_segmentation.append(UpperCAmelCase__       )
						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
