import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
					from PIL import Image

					from transformers import OwlViTImageProcessor, OwlViTProcessor





@require_vision
class       lowercase__		(     unittest.TestCase):


						def  __A ( self			:       List[str]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Tuple           =							tempfile.mkdtemp()

												# fmt: off
												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							['', 'l', 'o', 'w', 'e', 'r', 's', 't', 'i', 'd', 'n', 'lo', 'l</w>', 'w</w>', 'r</w>', 't</w>', 'low</w>', 'er</w>', 'lowest</w>', 'newer</w>', 'wider', '<unk>', '<|startoftext|>', '<|endoftext|>']
												# fmt: on
												SCREAMING_SNAKE_CASE							:					Dict           =							dict(zip(_A					,	range(len(_A		)		)		)		)
												SCREAMING_SNAKE_CASE							:					int           =							['#version: 0.2', 'l o', 'lo w</w>', 'e r</w>', '']
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							{'unk_token': '<unk>'}

												SCREAMING_SNAKE_CASE							:					Tuple           =							os.path.join(self.tmpdirname					,	VOCAB_FILES_NAMES['''vocab_file''']		)
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							os.path.join(self.tmpdirname					,	VOCAB_FILES_NAMES['''merges_file''']		)
												with open(self.vocab_file					,	'''w'''					,	encoding='''utf-8'''		) as fp:
																		fp.write(json.dumps(_A		) + '''\n'''		)
												with open(self.merges_file					,	'''w'''					,	encoding='''utf-8'''		) as fp:
																		fp.write('''\n'''.join(_A		)		)

												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							{
												    'do_resize': True,
												    'size': 20,
												    'do_center_crop': True,
												    'crop_size': 18,
												    'do_normalize': True,
												    'image_mean': [0.4814_5466, 0.457_8275, 0.4082_1073],
												    'image_std': [0.2686_2954, 0.2613_0258, 0.2757_7711],
												}
												SCREAMING_SNAKE_CASE							:					List[str]           =							os.path.join(self.tmpdirname					,	_A		)
												with open(self.image_processor_file					,	'''w'''					,	encoding='''utf-8'''		) as fp:
																		json.dump(_A					,	_A		)


						def  __A ( self			:       List[Any]					,	**UpperCamelCase__			:       Dict		):





												'''simple docstring'''





												return CLIPTokenizer.from_pretrained(self.tmpdirname					,	pad_token='''!'''					,	**_A		)


						def  __A ( self			:       Union[str, Any]					,	**UpperCamelCase__			:       Optional[Any]		):





												'''simple docstring'''





												return CLIPTokenizerFast.from_pretrained(self.tmpdirname					,	pad_token='''!'''					,	**_A		)


						def  __A ( self			:       Dict					,	**UpperCamelCase__			:       Union[str, Any]		):





												'''simple docstring'''





												return OwlViTImageProcessor.from_pretrained(self.tmpdirname					,	**_A		)


						def  __A ( self			:       int		):





												'''simple docstring'''





												shutil.rmtree(self.tmpdirname		)


						def  __A ( self			:       List[str]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					List[Any]           =							[np.random.randint(255					,	size=(3, 30, 400)					,	dtype=np.uinta		)]

												SCREAMING_SNAKE_CASE							:					Optional[int]           =							[Image.fromarray(np.moveaxis(_A					,	0					,	-1		)		) for x in image_inputs]

												return image_inputs


						def  __A ( self			:       int		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					List[str]           =							self.get_tokenizer()
												SCREAMING_SNAKE_CASE							:					Dict           =							self.get_rust_tokenizer()
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							self.get_image_processor()

												SCREAMING_SNAKE_CASE							:					Dict           =							OwlViTProcessor(tokenizer=_A					,	image_processor=_A		)
												processor_slow.save_pretrained(self.tmpdirname		)
												SCREAMING_SNAKE_CASE							:					Optional[int]           =							OwlViTProcessor.from_pretrained(self.tmpdirname					,	use_fast=_A		)

												SCREAMING_SNAKE_CASE							:					Any           =							OwlViTProcessor(tokenizer=_A					,	image_processor=_A		)
												processor_fast.save_pretrained(self.tmpdirname		)
												SCREAMING_SNAKE_CASE							:					Optional[int]           =							OwlViTProcessor.from_pretrained(self.tmpdirname		)

												self.assertEqual(processor_slow.tokenizer.get_vocab()					,	tokenizer_slow.get_vocab()		)
												self.assertEqual(processor_fast.tokenizer.get_vocab()					,	tokenizer_fast.get_vocab()		)
												self.assertEqual(tokenizer_slow.get_vocab()					,	tokenizer_fast.get_vocab()		)
												self.assertIsInstance(processor_slow.tokenizer					,	_A		)
												self.assertIsInstance(processor_fast.tokenizer					,	_A		)

												self.assertEqual(processor_slow.image_processor.to_json_string()					,	image_processor.to_json_string()		)
												self.assertEqual(processor_fast.image_processor.to_json_string()					,	image_processor.to_json_string()		)
												self.assertIsInstance(processor_slow.image_processor					,	_A		)
												self.assertIsInstance(processor_fast.image_processor					,	_A		)


						def  __A ( self			:       List[Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Tuple           =							OwlViTProcessor(tokenizer=self.get_tokenizer()					,	image_processor=self.get_image_processor()		)
												processor.save_pretrained(self.tmpdirname		)

												SCREAMING_SNAKE_CASE							:					str           =							self.get_tokenizer(bos_token='''(BOS)'''					,	eos_token='''(EOS)'''		)
												SCREAMING_SNAKE_CASE							:					int           =							self.get_image_processor(do_normalize=_A		)

												SCREAMING_SNAKE_CASE							:					int           =							OwlViTProcessor.from_pretrained(
												    self.tmpdirname					,	bos_token='''(BOS)'''					,	eos_token='''(EOS)'''					,	do_normalize=_A		)

												self.assertEqual(processor.tokenizer.get_vocab()					,	tokenizer_add_kwargs.get_vocab()		)
												self.assertIsInstance(processor.tokenizer					,	_A		)

												self.assertEqual(processor.image_processor.to_json_string()					,	image_processor_add_kwargs.to_json_string()		)
												self.assertIsInstance(processor.image_processor					,	_A		)


						def  __A ( self			:       int		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					List[str]           =							self.get_image_processor()
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							self.get_tokenizer()

												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							OwlViTProcessor(tokenizer=_A					,	image_processor=_A		)

												SCREAMING_SNAKE_CASE							:					List[Any]           =							self.prepare_image_inputs()

												SCREAMING_SNAKE_CASE							:					Any           =							image_processor(_A					,	return_tensors='''np'''		)
												SCREAMING_SNAKE_CASE							:					Tuple           =							processor(images=_A					,	return_tensors='''np'''		)

												for key in input_image_proc.keys():
																		self.assertAlmostEqual(input_image_proc[key].sum()					,	input_processor[key].sum()					,	delta=1E-2		)


						def  __A ( self			:       str		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Tuple           =							self.get_image_processor()
												SCREAMING_SNAKE_CASE							:					int           =							self.get_tokenizer()

												SCREAMING_SNAKE_CASE							:					Optional[int]           =							OwlViTProcessor(tokenizer=_A					,	image_processor=_A		)

												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							'lower newer'

												SCREAMING_SNAKE_CASE							:					Any           =							processor(text=_A					,	return_tensors='''np'''		)

												SCREAMING_SNAKE_CASE							:					Dict           =							tokenizer(_A					,	return_tensors='''np'''		)

												for key in encoded_tok.keys():
																		self.assertListEqual(encoded_tok[key][0].tolist()					,	encoded_processor[key][0].tolist()		)


						def  __A ( self			:       Union[str, Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Optional[int]           =							self.get_image_processor()
												SCREAMING_SNAKE_CASE							:					List[str]           =							self.get_tokenizer()

												SCREAMING_SNAKE_CASE							:					Tuple           =							OwlViTProcessor(tokenizer=_A					,	image_processor=_A		)

												SCREAMING_SNAKE_CASE							:					Tuple           =							'lower newer'
												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							self.prepare_image_inputs()

												SCREAMING_SNAKE_CASE							:					List[Any]           =							processor(text=_A					,	images=_A		)

												self.assertListEqual(list(inputs.keys()		)					,	['''input_ids''', '''attention_mask''', '''pixel_values''']		)

												# test if it raises when no input is passed
												with pytest.raises(_A		):
																		processor()


						def  __A ( self			:       Union[str, Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Optional[int]           =							'google/owlvit-base-patch32'
												SCREAMING_SNAKE_CASE							:					str           =							OwlViTProcessor.from_pretrained(_A		)

												SCREAMING_SNAKE_CASE							:					Any           =							['cat', 'nasa badge']
												SCREAMING_SNAKE_CASE							:					List[Any]           =							processor(text=_A		)

												SCREAMING_SNAKE_CASE							:					Dict           =							16
												self.assertListEqual(list(inputs.keys()		)					,	['''input_ids''', '''attention_mask''']		)
												self.assertEqual(inputs['''input_ids'''].shape					,	(2, seq_length)		)

												# test if it raises when no input is passed
												with pytest.raises(_A		):
																		processor()


						def  __A ( self			:       List[str]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Tuple           =							'google/owlvit-base-patch32'
												SCREAMING_SNAKE_CASE							:					Any           =							OwlViTProcessor.from_pretrained(_A		)

												SCREAMING_SNAKE_CASE							:					int           =							[['cat', 'nasa badge'], ['person']]
												SCREAMING_SNAKE_CASE							:					str           =							processor(text=_A		)

												SCREAMING_SNAKE_CASE							:					int           =							16
												SCREAMING_SNAKE_CASE							:					Optional[int]           =							len(_A		)
												SCREAMING_SNAKE_CASE							:					int           =							max([len(_A		) for texts in input_texts]		)

												self.assertListEqual(list(inputs.keys()		)					,	['''input_ids''', '''attention_mask''']		)
												self.assertEqual(inputs['''input_ids'''].shape					,	(batch_size * num_max_text_queries, seq_length)		)

												# test if it raises when no input is passed
												with pytest.raises(_A		):
																		processor()


						def  __A ( self			:       Optional[int]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					int           =							'google/owlvit-base-patch32'
												SCREAMING_SNAKE_CASE							:					List[str]           =							OwlViTProcessor.from_pretrained(_A		)

												SCREAMING_SNAKE_CASE							:					Tuple           =							['cat', 'nasa badge']
												SCREAMING_SNAKE_CASE							:					Dict           =							processor(text=_A		)

												SCREAMING_SNAKE_CASE							:					Tuple           =							16
												SCREAMING_SNAKE_CASE							:					str           =							inputs['input_ids']
												SCREAMING_SNAKE_CASE							:					str           =							[
												    [4_9406, 2368, 4_9407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
												    [4_9406, 6841, 1_1301, 4_9407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
												]

												self.assertListEqual(list(inputs.keys()		)					,	['''input_ids''', '''attention_mask''']		)
												self.assertEqual(inputs['''input_ids'''].shape					,	(2, seq_length)		)
												self.assertListEqual(list(input_ids[0]		)					,	predicted_ids[0]		)
												self.assertListEqual(list(input_ids[1]		)					,	predicted_ids[1]		)


						def  __A ( self			:       int		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Dict           =							self.get_image_processor()
												SCREAMING_SNAKE_CASE							:					Optional[int]           =							self.get_tokenizer()

												SCREAMING_SNAKE_CASE							:					Dict           =							OwlViTProcessor(tokenizer=_A					,	image_processor=_A		)

												SCREAMING_SNAKE_CASE							:					Any           =							self.prepare_image_inputs()
												SCREAMING_SNAKE_CASE							:					Tuple           =							self.prepare_image_inputs()

												SCREAMING_SNAKE_CASE							:					Any           =							processor(images=_A					,	query_images=_A		)

												self.assertListEqual(list(inputs.keys()		)					,	['''query_pixel_values''', '''pixel_values''']		)

												# test if it raises when no input is passed
												with pytest.raises(_A		):
																		processor()



						def  __A ( self			:       Union[str, Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							self.get_image_processor()
												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							self.get_tokenizer()

												SCREAMING_SNAKE_CASE							:					Optional[int]           =							OwlViTProcessor(tokenizer=_A					,	image_processor=_A		)

												SCREAMING_SNAKE_CASE							:					int           =							[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

												SCREAMING_SNAKE_CASE							:					Any           =							processor.batch_decode(_A		)
												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							tokenizer.batch_decode(_A		)

												self.assertListEqual(_A					,	_A		)






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


__UpperCamelCase	: int    		=  logging.get_logger(__name__)
def    A			(					_lowercase	,						_lowercase	,						_lowercase	,						_lowercase		):
						def constraint_to_multiple_of(_lowercase	,						_lowercase	,						_lowercase=0	,						_lowercase=None		):
												SCREAMING_SNAKE_CASE							:					int           =							round(val / multiple		) * multiple

												if max_val is not None and x > max_val:
																		SCREAMING_SNAKE_CASE							:					Dict           =							math.floor(val / multiple		) * multiple

												if x < min_val:
																		SCREAMING_SNAKE_CASE							:					Optional[Any]           =							math.ceil(val / multiple		) * multiple

												return x

						SCREAMING_SNAKE_CASE							:					Optional[Any]           =							(output_size, output_size) if isinstance(_lowercase	,						_lowercase		) else output_size

						SCREAMING_SNAKE_CASE       ,						SCREAMING_SNAKE_CASE							:					Optional[int]           =							get_image_size(_lowercase		)
						SCREAMING_SNAKE_CASE       ,						SCREAMING_SNAKE_CASE							:					Optional[int]           =							output_size

						# determine new height and width
						SCREAMING_SNAKE_CASE							:					Dict           =							output_height / input_height
						SCREAMING_SNAKE_CASE							:					Optional[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							:					List[Any]           =							scale_width
												else:
																		# fit height
																		SCREAMING_SNAKE_CASE							:					List[Any]           =							scale_height

						SCREAMING_SNAKE_CASE							:					List[str]           =							constraint_to_multiple_of(scale_height * input_height	,						multiple=_lowercase		)
						SCREAMING_SNAKE_CASE							:					Optional[int]           =							constraint_to_multiple_of(scale_width * input_width	,						multiple=_lowercase		)

						return (new_height, new_width)





class       lowercase__		(     UpperCamelCase_):
						UpperCamelCase_  =	["""pixel_values"""]


						def __init__( self			:       int					,	UpperCamelCase__			:       bool = True					,	UpperCamelCase__			:       Dict[str, int] = None					,	UpperCamelCase__			:       PILImageResampling = PILImageResampling.BILINEAR					,	UpperCamelCase__			:       bool = False					,	UpperCamelCase__			:       int = 1					,	UpperCamelCase__			:       bool = True					,	UpperCamelCase__			:       Union[int, float] = 1 / 255					,	UpperCamelCase__			:       bool = True					,	UpperCamelCase__			:       Optional[Union[float, List[float]]] = None					,	UpperCamelCase__			:       Optional[Union[float, List[float]]] = None					,	**UpperCamelCase__			:       Optional[int]					,	):





												'''simple docstring'''





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


						def  __A ( self			:       Optional[Any]					,	UpperCamelCase__			:       np.ndarray					,	UpperCamelCase__			:       Dict[str, int]					,	UpperCamelCase__			:       bool = False					,	UpperCamelCase__			:       int = 1					,	UpperCamelCase__			:       PILImageResampling = PILImageResampling.BICUBIC					,	UpperCamelCase__			:       Optional[Union[str, ChannelDimension]] = None					,	**UpperCamelCase__			:       Union[str, Any]					,	):





												'''simple docstring'''





												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							:					Any           =							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  __A ( self			:       Dict					,	UpperCamelCase__			:       np.ndarray					,	UpperCamelCase__			:       Union[int, float]					,	UpperCamelCase__			:       Optional[Union[str, ChannelDimension]] = None					,	**UpperCamelCase__			:       str					,	):





												'''simple docstring'''





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


						def  __A ( self			:       Any					,	UpperCamelCase__			:       np.ndarray					,	UpperCamelCase__			:       Union[float, List[float]]					,	UpperCamelCase__			:       Union[float, List[float]]					,	UpperCamelCase__			:       Optional[Union[str, ChannelDimension]] = None					,	**UpperCamelCase__			:       List[str]					,	):





												'''simple docstring'''





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


						def  __A ( self			:       Optional[Any]					,	UpperCamelCase__			:       ImageInput					,	UpperCamelCase__			:       bool = None					,	UpperCamelCase__			:       int = None					,	UpperCamelCase__			:       bool = None					,	UpperCamelCase__			:       int = None					,	UpperCamelCase__			:       PILImageResampling = None					,	UpperCamelCase__			:       bool = None					,	UpperCamelCase__			:       float = None					,	UpperCamelCase__			:       bool = None					,	UpperCamelCase__			:       Optional[Union[float, List[float]]] = None					,	UpperCamelCase__			:       Optional[Union[float, List[float]]] = None					,	UpperCamelCase__			:       Optional[Union[str, TensorType]] = None					,	UpperCamelCase__			:       ChannelDimension = ChannelDimension.FIRST					,	**UpperCamelCase__			:       Optional[int]					,	):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					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							:					Union[str, Any]           =							get_size_dict(UpperCamelCase__		)
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							keep_aspect_ratio if keep_aspect_ratio is not None else self.keep_aspect_ratio
												SCREAMING_SNAKE_CASE							:					List[str]           =							ensure_multiple_of if ensure_multiple_of is not None else self.ensure_multiple_of
												SCREAMING_SNAKE_CASE							:					Tuple           =							resample if resample is not None else self.resample
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							do_rescale if do_rescale is not None else self.do_rescale
												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							rescale_factor if rescale_factor is not None else self.rescale_factor
												SCREAMING_SNAKE_CASE							:					str           =							do_normalize if do_normalize is not None else self.do_normalize
												SCREAMING_SNAKE_CASE							:					List[Any]           =							image_mean if image_mean is not None else self.image_mean
												SCREAMING_SNAKE_CASE							:					List[Any]           =							image_std if image_std is not None else self.image_std

												SCREAMING_SNAKE_CASE							:					Dict           =							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							:					Tuple           =							[to_numpy_array(UpperCamelCase__		) for image in images]

												if do_resize:
																		SCREAMING_SNAKE_CASE							:					Dict           =							[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							:					Optional[int]           =							[to_channel_dimension_format(UpperCamelCase__					,	UpperCamelCase__		) for image in images]

												SCREAMING_SNAKE_CASE							:					Tuple           =							{'''pixel_values''': images}
												return BatchFeature(data=UpperCamelCase__					,	tensor_type=UpperCamelCase__		)



						def  __A ( self			:       Tuple					,	UpperCamelCase__			:       Union[str, Any]					,	UpperCamelCase__			:       List[Tuple] = None		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Dict           =							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							:					List[Any]           =							target_sizes.numpy()

																		SCREAMING_SNAKE_CASE							:					Optional[int]           =							[]

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

												return semantic_segmentation





