



'''simple docstring'''





import unittest

from parameterized import parameterized

from transformers import OpenLlamaConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 OpenLlamaForCausalLM, OpenLlamaForSequenceClassification, OpenLlamaModel



class  lowerCamelCase__    :




		'''simple docstring'''



		def __init__(self	,__lowerCamelCase	,__lowerCamelCase=13	,__lowerCamelCase=7	,__lowerCamelCase=True	,__lowerCamelCase=True	,__lowerCamelCase=False	,__lowerCamelCase=True	,__lowerCamelCase=99	,__lowerCamelCase=32	,__lowerCamelCase=5	,__lowerCamelCase=4	,__lowerCamelCase=37	,__lowerCamelCase="gelu"	,__lowerCamelCase=0.1	,__lowerCamelCase=0.1	,__lowerCamelCase=5_12	,__lowerCamelCase=16	,__lowerCamelCase=2	,__lowerCamelCase=0.02	,__lowerCamelCase=3	,__lowerCamelCase=4	,__lowerCamelCase=None	,)  ->    str:

						"""simple docstring"""






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



		def 	lowerCAmelCase__   (self				)  ->    str:

						"""simple docstring"""






						lowerCAmelCase__  :       List[str]				=  ids_tensor([self.batch_size, self.seq_length]	,self.vocab_size				)

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

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

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

						lowerCAmelCase__  :       List[str]				=  self.get_config()

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



		def 	lowerCAmelCase__   (self				)  ->    Dict:

						"""simple docstring"""






						return OpenLlamaConfig(
						    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=lowercase__	,initializer_range=self.initializer_range	,use_stable_embedding=lowercase__	,)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)  ->    List[Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       Optional[int]				=  OpenLlamaModel(config=lowercase__				)
						model.to(lowercase__				)
						model.eval()
						lowerCAmelCase__  :       Dict				=  model(lowercase__	,attention_mask=lowercase__				)
						lowerCAmelCase__  :       Optional[int]				=  model(lowercase__				)
						self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, self.seq_length, self.hidden_size)				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,)  ->    Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       List[Any]				=  True
						lowerCAmelCase__  :       Tuple				=  OpenLlamaModel(lowercase__				)
						model.to(lowercase__				)
						model.eval()
						lowerCAmelCase__  :       List[Any]				=  model(
						    lowercase__	,attention_mask=lowercase__	,encoder_hidden_states=lowercase__	,encoder_attention_mask=lowercase__	,)
						lowerCAmelCase__  :       Dict				=  model(
						    lowercase__	,attention_mask=lowercase__	,encoder_hidden_states=lowercase__	,)
						lowerCAmelCase__  :       Any				=  model(lowercase__	,attention_mask=lowercase__				)
						self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, self.seq_length, self.hidden_size)				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,)  ->    List[str]:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  OpenLlamaForCausalLM(config=lowercase__				)
						model.to(lowercase__				)
						model.eval()
						lowerCAmelCase__  :       Dict				=  model(lowercase__	,attention_mask=lowercase__	,labels=lowercase__				)
						self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.seq_length, self.vocab_size)				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       List[str]				=  True
						lowerCAmelCase__  :       Dict				=  True
						lowerCAmelCase__  :       int				=  OpenLlamaForCausalLM(config=lowercase__				)
						model.to(lowercase__				)
						model.eval()

						# first forward pass
						lowerCAmelCase__  :       Optional[Any]				=  model(
						    lowercase__	,attention_mask=lowercase__	,encoder_hidden_states=lowercase__	,encoder_attention_mask=lowercase__	,use_cache=lowercase__	,)
						lowerCAmelCase__  :       Optional[int]				=  outputs.past_key_values

						# create hypothetical multiple next token and extent to next_input_ids
						lowerCAmelCase__  :       List[str]				=  ids_tensor((self.batch_size, 3)	,config.vocab_size				)
						lowerCAmelCase__  :       List[Any]				=  ids_tensor((self.batch_size, 3)	,vocab_size=2				)

						# append to next input_ids and
						lowerCAmelCase__  :       Optional[Any]				=  torch.cat([input_ids, next_tokens]	,dim=-1				)
						lowerCAmelCase__  :       Optional[Any]				=  torch.cat([input_mask, next_mask]	,dim=-1				)

						lowerCAmelCase__  :       List[str]				=  model(
						    lowercase__	,attention_mask=lowercase__	,encoder_hidden_states=lowercase__	,encoder_attention_mask=lowercase__	,output_hidden_states=lowercase__	,)["""hidden_states"""][0]
						lowerCAmelCase__  :       List[Any]				=  model(
						    lowercase__	,attention_mask=lowercase__	,encoder_hidden_states=lowercase__	,encoder_attention_mask=lowercase__	,past_key_values=lowercase__	,output_hidden_states=lowercase__	,)["""hidden_states"""][0]

						# select random slice
						lowerCAmelCase__  :       Union[str, Any]				=  ids_tensor((1,)	,output_from_past.shape[-1]				).item()
						lowerCAmelCase__  :       str				=  output_from_no_past[:, -3:, random_slice_idx].detach()
						lowerCAmelCase__  :       List[Any]				=  output_from_past[:, :, random_slice_idx].detach()

						self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]				)

						# test that outputs are equal for slice
						self.parent.assertTrue(torch.allclose(lowercase__	,lowercase__	,atol=1e-3				)				)



		def 	lowerCAmelCase__   (self				)  ->    Tuple:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  self.prepare_config_and_inputs()
						(
						    lowerCAmelCase__			
						)  :       Union[str, Any]				=  config_and_inputs
						lowerCAmelCase__  :       Dict				=  {"""input_ids""": input_ids, """attention_mask""": input_mask}
						return config, inputs_dict



@require_torch
class  lowerCamelCase__    (							_UpperCAmelCase   ,       _UpperCAmelCase   ,       _UpperCAmelCase   ,       unittest.TestCase):




		'''simple docstring'''



		snake_case_			=(
		    (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
		)
		snake_case_			=(OpenLlamaForCausalLM,) if is_torch_available() else ()
		snake_case_			=(
		    {
		        """feature-extraction""": OpenLlamaModel,
		        """text-classification""": OpenLlamaForSequenceClassification,
		        """text-generation""": OpenLlamaForCausalLM,
		        """zero-shot""": OpenLlamaForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		snake_case_			=False
		snake_case_			=False



		def 	lowerCAmelCase__   (self				)  ->    Optional[Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       Tuple				=  OpenLlamaModelTester(self				)
						lowerCAmelCase__  :       Optional[int]				=  ConfigTester(self	,config_class=lowercase__	,hidden_size=37				)



		def 	lowerCAmelCase__   (self				)  ->    Any:

						"""simple docstring"""






						self.config_tester.run_common_tests()



		def 	lowerCAmelCase__   (self				)  ->    Optional[int]:

						"""simple docstring"""






						lowerCAmelCase__  :       Dict				=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowercase__				)



		def 	lowerCAmelCase__   (self				)  ->    str:

						"""simple docstring"""






						lowerCAmelCase__  :       Any				=  self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
										lowerCAmelCase__  :       List[str]				=  type
										self.model_tester.create_and_check_model(*lowercase__				)



		def 	lowerCAmelCase__   (self				)  ->    Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       Dict				=  self.model_tester.prepare_config_and_inputs_for_common()
						lowerCAmelCase__  :       Optional[Any]				=  3
						lowerCAmelCase__  :       Dict				=  input_dict["""input_ids"""]
						lowerCAmelCase__  :       List[str]				=  input_ids.ne(1				).to(lowercase__				)
						lowerCAmelCase__  :       Optional[int]				=  ids_tensor([self.model_tester.batch_size]	,self.model_tester.type_sequence_label_size				)
						lowerCAmelCase__  :       List[str]				=  OpenLlamaForSequenceClassification(lowercase__				)
						model.to(lowercase__				)
						model.eval()
						lowerCAmelCase__  :       List[str]				=  model(lowercase__	,attention_mask=lowercase__	,labels=lowercase__				)
						self.assertEqual(result.logits.shape	,(self.model_tester.batch_size, self.model_tester.num_labels)				)



		def 	lowerCAmelCase__   (self				)  ->    Tuple:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  self.model_tester.prepare_config_and_inputs_for_common()
						lowerCAmelCase__  :       int				=  3
						lowerCAmelCase__  :       str				=  """single_label_classification"""
						lowerCAmelCase__  :       Optional[Any]				=  input_dict["""input_ids"""]
						lowerCAmelCase__  :       Optional[int]				=  input_ids.ne(1				).to(lowercase__				)
						lowerCAmelCase__  :       Optional[int]				=  ids_tensor([self.model_tester.batch_size]	,self.model_tester.type_sequence_label_size				)
						lowerCAmelCase__  :       Optional[Any]				=  OpenLlamaForSequenceClassification(lowercase__				)
						model.to(lowercase__				)
						model.eval()
						lowerCAmelCase__  :       Dict				=  model(lowercase__	,attention_mask=lowercase__	,labels=lowercase__				)
						self.assertEqual(result.logits.shape	,(self.model_tester.batch_size, self.model_tester.num_labels)				)



		def 	lowerCAmelCase__   (self				)  ->    List[str]:

						"""simple docstring"""






						lowerCAmelCase__  :       List[Any]				=  self.model_tester.prepare_config_and_inputs_for_common()
						lowerCAmelCase__  :       int				=  3
						lowerCAmelCase__  :       Any				=  """multi_label_classification"""
						lowerCAmelCase__  :       Optional[int]				=  input_dict["""input_ids"""]
						lowerCAmelCase__  :       Tuple				=  input_ids.ne(1				).to(lowercase__				)
						lowerCAmelCase__  :       Union[str, Any]				=  ids_tensor(
						    [self.model_tester.batch_size, config.num_labels]	,self.model_tester.type_sequence_label_size				).to(torch.float				)
						lowerCAmelCase__  :       Any				=  OpenLlamaForSequenceClassification(lowercase__				)
						model.to(lowercase__				)
						model.eval()
						lowerCAmelCase__  :       str				=  model(lowercase__	,attention_mask=lowercase__	,labels=lowercase__				)
						self.assertEqual(result.logits.shape	,(self.model_tester.batch_size, self.model_tester.num_labels)				)



		@unittest.skip('''Open-Llama buffers include complex numbers, which breaks this test'''				)
		def 	lowerCAmelCase__   (self				)  ->    int:

						"""simple docstring"""






						pass



		@parameterized.expand([('''linear''',), ('''dynamic''',)]				)
		def 	lowerCAmelCase__   (self	,__lowerCamelCase				)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       int				=  self.model_tester.prepare_config_and_inputs_for_common()
						lowerCAmelCase__  :       List[Any]				=  ids_tensor([1, 10]	,config.vocab_size				)
						lowerCAmelCase__  :       str				=  ids_tensor([1, int(config.max_position_embeddings * 1.5				)]	,config.vocab_size				)

						set_seed(42				)  # Fixed seed at init time so the two models get the same random weights
						lowerCAmelCase__  :       Tuple				=  OpenLlamaModel(lowercase__				)
						original_model.to(lowercase__				)
						original_model.eval()
						lowerCAmelCase__  :       str				=  original_model(lowercase__				).last_hidden_state
						lowerCAmelCase__  :       Optional[Any]				=  original_model(lowercase__				).last_hidden_state

						set_seed(42				)  # Fixed seed at init time so the two models get the same random weights
						lowerCAmelCase__  :       Union[str, Any]				=  {"""type""": scaling_type, """factor""": 10.0}
						lowerCAmelCase__  :       int				=  OpenLlamaModel(lowercase__				)
						scaled_model.to(lowercase__				)
						scaled_model.eval()
						lowerCAmelCase__  :       str				=  scaled_model(lowercase__				).last_hidden_state
						lowerCAmelCase__  :       Optional[Any]				=  scaled_model(lowercase__				).last_hidden_state

						# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
						# maximum sequence length, so the outputs for the short input should match.
						if scaling_type == "dynamic":
										self.assertTrue(torch.allclose(lowercase__	,lowercase__	,atol=1e-5				)				)
						else:
										self.assertFalse(torch.allclose(lowercase__	,lowercase__	,atol=1e-5				)				)

						# The output should be different for long inputs
						self.assertFalse(torch.allclose(lowercase__	,lowercase__	,atol=1e-5				)				)






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,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging


if is_torch_available():
							import torch


__snake_case       :	List[Any]            =logging.get_logger(__name__)



class  lowerCamelCase__    (							lowerCamelCase__):




		'''simple docstring'''



		snake_case_			=["""pixel_values"""]



		def __init__(self	,__lowerCamelCase = True	,__lowerCamelCase = None	,__lowerCamelCase = PILImageResampling.BILINEAR	,__lowerCamelCase = True	,__lowerCamelCase = None	,__lowerCamelCase = True	,__lowerCamelCase = 1 / 2_55	,__lowerCamelCase = True	,__lowerCamelCase = None	,__lowerCamelCase = None	,**__lowerCamelCase	,)  ->    None:

						"""simple docstring"""






						super().__init__(**__lowerCamelCase				)
						lowerCAmelCase__  :       List[Any]				=  size if size is not None else {'''shortest_edge''': 2_56}
						lowerCAmelCase__  :       Any				=  get_size_dict(__lowerCamelCase	,default_to_square=__lowerCamelCase				)
						lowerCAmelCase__  :       Optional[Any]				=  crop_size if crop_size is not None else {'''height''': 2_24, '''width''': 2_24}
						lowerCAmelCase__  :       Any				=  get_size_dict(__lowerCamelCase	,param_name='''crop_size'''				)
						lowerCAmelCase__  :       Dict				=  do_resize
						lowerCAmelCase__  :       str				=  size
						lowerCAmelCase__  :       Tuple				=  resample
						lowerCAmelCase__  :       List[Any]				=  do_center_crop
						lowerCAmelCase__  :       Dict				=  crop_size
						lowerCAmelCase__  :       Optional[int]				=  do_rescale
						lowerCAmelCase__  :       List[str]				=  rescale_factor
						lowerCAmelCase__  :       List[Any]				=  do_normalize
						lowerCAmelCase__  :       Optional[Any]				=  image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
						lowerCAmelCase__  :       str				=  image_std if image_std is not None else IMAGENET_STANDARD_STD



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase = PILImageResampling.BICUBIC	,__lowerCamelCase = None	,**__lowerCamelCase	,)  ->    np.ndarray:

						"""simple docstring"""






						lowerCAmelCase__  :       Dict				=  get_size_dict(__lowerCamelCase	,default_to_square=__lowerCamelCase				)
						if "shortest_edge" not in size:
										raise ValueError(f"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""				)
						lowerCAmelCase__  :       str				=  get_resize_output_image_size(__lowerCamelCase	,size=size['''shortest_edge''']	,default_to_square=__lowerCamelCase				)
						return resize(__lowerCamelCase	,size=__lowerCamelCase	,resample=__lowerCamelCase	,data_format=__lowerCamelCase	,**__lowerCamelCase				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase = None	,**__lowerCamelCase	,)  ->    np.ndarray:

						"""simple docstring"""






						lowerCAmelCase__  :       Union[str, Any]				=  get_size_dict(__lowerCamelCase				)
						if "height" not in size or "width" not in size:
										raise ValueError(f"""The `size` parameter must contain the keys `height` and `width`. Got {size.keys()}"""				)
						return center_crop(__lowerCamelCase	,size=(size['''height'''], size['''width'''])	,data_format=__lowerCamelCase	,**__lowerCamelCase				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase = None	,**__lowerCamelCase				)  ->    np.ndarray:

						"""simple docstring"""






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



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase = None	,**__lowerCamelCase	,)  ->    np.ndarray:

						"""simple docstring"""






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



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = None	,__lowerCamelCase = ChannelDimension.FIRST	,**__lowerCamelCase	,)  ->    Optional[Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       Optional[int]				=  do_resize if do_resize is not None else self.do_resize
						lowerCAmelCase__  :       Optional[int]				=  size if size is not None else self.size
						lowerCAmelCase__  :       Union[str, Any]				=  get_size_dict(__lowerCamelCase	,default_to_square=__lowerCamelCase				)
						lowerCAmelCase__  :       Dict				=  resample if resample is not None else self.resample
						lowerCAmelCase__  :       Union[str, Any]				=  do_center_crop if do_center_crop is not None else self.do_center_crop
						lowerCAmelCase__  :       Any				=  crop_size if crop_size is not None else self.crop_size
						lowerCAmelCase__  :       List[str]				=  get_size_dict(__lowerCamelCase	,param_name='''crop_size'''				)
						lowerCAmelCase__  :       List[str]				=  do_rescale if do_rescale is not None else self.do_rescale
						lowerCAmelCase__  :       str				=  rescale_factor if rescale_factor is not None else self.rescale_factor
						lowerCAmelCase__  :       int				=  do_normalize if do_normalize is not None else self.do_normalize
						lowerCAmelCase__  :       Optional[Any]				=  image_mean if image_mean is not None else self.image_mean
						lowerCAmelCase__  :       List[Any]				=  image_std if image_std is not None else self.image_std

						lowerCAmelCase__  :       Any				=  make_list_of_images(__lowerCamelCase				)

						if not valid_images(__lowerCamelCase				):
										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_center_crop and crop_size is None:
										raise ValueError('''Crop size must be specified if do_center_crop 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.
						lowerCAmelCase__  :       Union[str, Any]				=  [to_numpy_array(__lowerCamelCase				) for image in images]

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

						if do_center_crop:
										lowerCAmelCase__  :       List[Any]				=  [self.center_crop(image=__lowerCamelCase	,size=__lowerCamelCase				) for image in images]

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

						if do_normalize:
										lowerCAmelCase__  :       Tuple				=  [self.normalize(image=__lowerCamelCase	,mean=__lowerCamelCase	,std=__lowerCamelCase				) for image in images]

						lowerCAmelCase__  :       int				=  [to_channel_dimension_format(__lowerCamelCase	,__lowerCamelCase				) for image in images]

						lowerCAmelCase__  :       int				=  {'''pixel_values''': images}
						return BatchFeature(data=__lowerCamelCase	,tensor_type=__lowerCamelCase				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase = None				)  ->    Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       Optional[int]				=  outputs.logits

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

										if is_torch_tensor(__lowerCamelCase				):
														lowerCAmelCase__  :       str				=  target_sizes.numpy()

										lowerCAmelCase__  :       Optional[Any]				=  []

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

						return semantic_segmentation

