



"""simple docstring"""

import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


A_						:    Any				=      logging.get_logger(__name__)

A_						:    int				=      {
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}
class     lowerCAmelCase__						(	_lowerCamelCase ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		List[Any]  						= '''altclip_text_model'''





	def __init__(      self				:       Dict     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=250_002     ,       _SCREAMING_SNAKE_CASE				:       List[Any]=1_024     ,       _SCREAMING_SNAKE_CASE				:       List[str]=24     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=16     ,       _SCREAMING_SNAKE_CASE				:       Dict=4_096     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]="gelu"     ,       _SCREAMING_SNAKE_CASE				:       Any=0.1     ,       _SCREAMING_SNAKE_CASE				:       List[Any]=0.1     ,       _SCREAMING_SNAKE_CASE				:       List[str]=514     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=1     ,       _SCREAMING_SNAKE_CASE				:       List[str]=0.0_2     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]=0.0_2     ,       _SCREAMING_SNAKE_CASE				:       List[str]=1E-0_5     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]=1     ,       _SCREAMING_SNAKE_CASE				:       List[Any]=0     ,       _SCREAMING_SNAKE_CASE				:       Tuple=2     ,       _SCREAMING_SNAKE_CASE				:       int="absolute"     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]=True     ,       _SCREAMING_SNAKE_CASE				:       Dict=768     ,       **_SCREAMING_SNAKE_CASE				:       Optional[Any]     ,       )						->	Optional[int]:





					"""simple docstring"""


					super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE     ,       bos_token_id=_SCREAMING_SNAKE_CASE     ,       eos_token_id=_SCREAMING_SNAKE_CASE     ,       **_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Any							=     vocab_size
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     hidden_size
					SCREAMING_SNAKE_CASE						:							List[str]							=     num_hidden_layers
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     num_attention_heads
					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     hidden_act
					SCREAMING_SNAKE_CASE						:							str							=     intermediate_size
					SCREAMING_SNAKE_CASE						:							Any							=     hidden_dropout_prob
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     attention_probs_dropout_prob
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     max_position_embeddings
					SCREAMING_SNAKE_CASE						:							Any							=     type_vocab_size
					SCREAMING_SNAKE_CASE						:							Any							=     initializer_range
					SCREAMING_SNAKE_CASE						:							int							=     initializer_factor
					SCREAMING_SNAKE_CASE						:							int							=     layer_norm_eps
					SCREAMING_SNAKE_CASE						:							Dict							=     position_embedding_type
					SCREAMING_SNAKE_CASE						:							Any							=     use_cache
					SCREAMING_SNAKE_CASE						:							Dict							=     project_dim




class     lowerCAmelCase__						(	_lowerCamelCase ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		int  						= '''altclip_vision_model'''





	def __init__(      self				:       int     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]=768     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]=3_072     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=512     ,       _SCREAMING_SNAKE_CASE				:       List[Any]=12     ,       _SCREAMING_SNAKE_CASE				:       str=12     ,       _SCREAMING_SNAKE_CASE				:       Any=3     ,       _SCREAMING_SNAKE_CASE				:       str=224     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]=32     ,       _SCREAMING_SNAKE_CASE				:       List[str]="quick_gelu"     ,       _SCREAMING_SNAKE_CASE				:       List[Any]=1E-5     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=0.0     ,       _SCREAMING_SNAKE_CASE				:       str=0.0_2     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]=1.0     ,       **_SCREAMING_SNAKE_CASE				:       str     ,       )						->	Optional[int]:





					"""simple docstring"""


					super().__init__(**_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Tuple							=     hidden_size
					SCREAMING_SNAKE_CASE						:							List[Any]							=     intermediate_size
					SCREAMING_SNAKE_CASE						:							int							=     projection_dim
					SCREAMING_SNAKE_CASE						:							int							=     num_hidden_layers
					SCREAMING_SNAKE_CASE						:							Tuple							=     num_attention_heads
					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     num_channels
					SCREAMING_SNAKE_CASE						:							List[str]							=     patch_size
					SCREAMING_SNAKE_CASE						:							List[Any]							=     image_size
					SCREAMING_SNAKE_CASE						:							List[str]							=     initializer_range
					SCREAMING_SNAKE_CASE						:							int							=     initializer_factor
					SCREAMING_SNAKE_CASE						:							str							=     attention_dropout
					SCREAMING_SNAKE_CASE						:							Dict							=     layer_norm_eps
					SCREAMING_SNAKE_CASE						:							List[Any]							=     hidden_act







	@classmethod
	def 			_lowerCAmelCase     (      cls				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       Union[str, os.PathLike]     ,       **_SCREAMING_SNAKE_CASE				:       List[Any]    )						->	"PretrainedConfig":





					"""simple docstring"""


					cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE				,						SCREAMING_SNAKE_CASE						:							Any							=     cls.get_config_dict(_SCREAMING_SNAKE_CASE     ,       **_SCREAMING_SNAKE_CASE    )

					# get the vision config dict if we are loading from AltCLIPConfig
					if config_dict.get('model_type'    ) == "altclip":
									SCREAMING_SNAKE_CASE						:							List[Any]							=     config_dict['vision_config']

					if "model_type" in config_dict and hasattr(cls     ,       'model_type'    ) and config_dict["model_type"] != cls.model_type:
									logger.warning(
									    f"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
									    f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""    )

					return cls.from_dict(_SCREAMING_SNAKE_CASE     ,       **_SCREAMING_SNAKE_CASE    )




class     lowerCAmelCase__						(	_lowerCamelCase ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		str  						= '''altclip'''
	_SCREAMING_SNAKE_CASE	:		Union[str, Any]  						= True





	def __init__(      self				:       Dict     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]=None     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=None     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=768     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=2.6_5_9_2     ,       **_SCREAMING_SNAKE_CASE				:       int    )						->	Union[str, Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[int]							=     kwargs.pop('text_config_dict'     ,       _SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     kwargs.pop('vision_config_dict'     ,       _SCREAMING_SNAKE_CASE    )

					super().__init__(**_SCREAMING_SNAKE_CASE    )

					# Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
					# `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
					# cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
					if text_config_dict is not None:
									if text_config is None:
													SCREAMING_SNAKE_CASE						:							Optional[Any]							=     {}

									# This is the complete result when using `text_config_dict`.
									SCREAMING_SNAKE_CASE						:							Optional[Any]							=     AltCLIPTextConfig(**_SCREAMING_SNAKE_CASE    ).to_dict()

									# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
									for key, value in _text_config_dict.items():
													if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
																	# If specified in `text_config_dict`
																	if key in text_config_dict:
																					SCREAMING_SNAKE_CASE						:							Tuple							=     (
																					    f"""`{key}` is found in both `text_config_dict` and `text_config` but with different values. """
																					    f"""The value `text_config_dict[\"{key}\"]` will be used instead."""
																					)
																	# If inferred from default argument values (just to be super careful)
																	else:
																					SCREAMING_SNAKE_CASE						:							Any							=     (
																					    f"""`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The """
																					    f"""value `text_config[\"{key}\"]` will be overriden."""
																					)
																	logger.warning(_SCREAMING_SNAKE_CASE    )

            # Update all values in `text_config` with the ones in `_text_config_dict`.
									text_config.update(_text_config_dict    )

					if vision_config_dict is not None:
									if vision_config is None:
													SCREAMING_SNAKE_CASE						:							List[Any]							=     {}

									# This is the complete result when using `vision_config_dict`.
									SCREAMING_SNAKE_CASE						:							int							=     AltCLIPVisionConfig(**_SCREAMING_SNAKE_CASE    ).to_dict()
									# convert keys to string instead of integer
									if "id2label" in _vision_config_dict:
													SCREAMING_SNAKE_CASE						:							List[str]							=     {
													    str(_SCREAMING_SNAKE_CASE    ): value for key, value in _vision_config_dict['id2label'].items()
													}

									# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
									for key, value in _vision_config_dict.items():
													if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
																	# If specified in `vision_config_dict`
																	if key in vision_config_dict:
																					SCREAMING_SNAKE_CASE						:							Optional[int]							=     (
																					    f"""`{key}` is found in both `vision_config_dict` and `vision_config` but with different """
																					    f"""values. The value `vision_config_dict[\"{key}\"]` will be used instead."""
																					)
																	# If inferred from default argument values (just to be super careful)
																	else:
																					SCREAMING_SNAKE_CASE						:							Optional[int]							=     (
																					    f"""`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. """
																					    f"""The value `vision_config[\"{key}\"]` will be overriden."""
																					)
																	logger.warning(_SCREAMING_SNAKE_CASE    )

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
									vision_config.update(_vision_config_dict    )

					if text_config is None:
									SCREAMING_SNAKE_CASE						:							Tuple							=     {}
									logger.info('`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'    )

					if vision_config is None:
									SCREAMING_SNAKE_CASE						:							Dict							=     {}
									logger.info('`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.'    )

					SCREAMING_SNAKE_CASE						:							Dict							=     AltCLIPTextConfig(**_SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							int							=     AltCLIPVisionConfig(**_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							List[Any]							=     projection_dim
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     logit_scale_init_value
					SCREAMING_SNAKE_CASE						:							Dict							=     1.0





	@classmethod
	def 			_lowerCAmelCase     (      cls				:       Dict     ,       _SCREAMING_SNAKE_CASE				:       AltCLIPTextConfig     ,       _SCREAMING_SNAKE_CASE				:       AltCLIPVisionConfig     ,       **_SCREAMING_SNAKE_CASE				:       Optional[Any]    )						->	Tuple:





					"""simple docstring"""


					return cls(text_config=text_config.to_dict()     ,       vision_config=vision_config.to_dict()     ,       **_SCREAMING_SNAKE_CASE    )







	def 			_lowerCAmelCase     (      self				:       Any    )						->	Any:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							int							=     copy.deepcopy(self.__dict__    )
					SCREAMING_SNAKE_CASE						:							List[str]							=     self.text_config.to_dict()
					SCREAMING_SNAKE_CASE						:							Dict							=     self.vision_config.to_dict()
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     self.__class__.model_type
					return output










"""simple docstring"""

import unittest

import numpy as np
from datasets import load_dataset

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import BeitImageProcessor
class     lowerCAmelCase__						(	unittest.TestCase ):


	'''simple docstring'''







	def __init__(      self				:       Union[str, Any]     ,       _SCREAMING_SNAKE_CASE				:       Any     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]=7     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]=3     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]=18     ,       _SCREAMING_SNAKE_CASE				:       List[Any]=30     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]=400     ,       _SCREAMING_SNAKE_CASE				:       Dict=True     ,       _SCREAMING_SNAKE_CASE				:       str=None     ,       _SCREAMING_SNAKE_CASE				:       Any=True     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]=None     ,       _SCREAMING_SNAKE_CASE				:       Dict=True     ,       _SCREAMING_SNAKE_CASE				:       List[str]=[0.5, 0.5, 0.5]     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]=[0.5, 0.5, 0.5]     ,       _SCREAMING_SNAKE_CASE				:       List[Any]=False     ,       )						->	int:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							List[str]							=     size if size is not None else {'height': 20, 'width': 20}
					SCREAMING_SNAKE_CASE						:							int							=     crop_size if crop_size is not None else {'height': 18, 'width': 18}
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     parent
					SCREAMING_SNAKE_CASE						:							Dict							=     batch_size
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     num_channels
					SCREAMING_SNAKE_CASE						:							Tuple							=     image_size
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     min_resolution
					SCREAMING_SNAKE_CASE						:							List[str]							=     max_resolution
					SCREAMING_SNAKE_CASE						:							Tuple							=     do_resize
					SCREAMING_SNAKE_CASE						:							str							=     size
					SCREAMING_SNAKE_CASE						:							Dict							=     do_center_crop
					SCREAMING_SNAKE_CASE						:							List[Any]							=     crop_size
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     do_normalize
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     image_mean
					SCREAMING_SNAKE_CASE						:							Dict							=     image_std
					SCREAMING_SNAKE_CASE						:							Any							=     do_reduce_labels







	def 			_lowerCAmelCase     (      self				:       Dict    )						->	str:





					"""simple docstring"""


					return {
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_center_crop": self.do_center_crop,
					    "crop_size": self.crop_size,
					    "do_normalize": self.do_normalize,
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_reduce_labels": self.do_reduce_labels,
					}




def  __snake_case							(	)     ->       List[str]:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE						:							Dict							=     load_dataset('hf-internal-testing/fixtures_ade20k'							,		split='test'     )

				SCREAMING_SNAKE_CASE						:							Any							=     Image.open(dataset[0]['file']     )
				SCREAMING_SNAKE_CASE						:							int							=     Image.open(dataset[1]['file']     )

				return image, map
def  __snake_case							(	)     ->       Optional[Any]:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE						:							int							=     load_dataset('hf-internal-testing/fixtures_ade20k'							,		split='test'     )

				SCREAMING_SNAKE_CASE						:							Optional[int]							=     Image.open(ds[0]['file']     )
				SCREAMING_SNAKE_CASE						:							Optional[int]							=     Image.open(ds[1]['file']     )
				SCREAMING_SNAKE_CASE						:							Tuple							=     Image.open(ds[2]['file']     )
				SCREAMING_SNAKE_CASE						:							Tuple							=     Image.open(ds[3]['file']     )

				return [imagea, imagea], [mapa, mapa]







@require_torch
@require_vision
class     lowerCAmelCase__						(	_lowerCamelCase							,							unittest.TestCase ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		Tuple  						= BeitImageProcessor if is_vision_available() else None





	def 			_lowerCAmelCase     (      self				:       Optional[Any]    )						->	Dict:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							List[Any]							=     BeitImageProcessingTester(self    )





	@property
	def 			_lowerCAmelCase     (      self				:       Optional[int]    )						->	int:





					"""simple docstring"""


					return self.image_processor_tester.prepare_image_processor_dict()





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





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Any							=     self.image_processing_class(**self.image_processor_dict    )
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,       'do_resize'    )    )
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,       'size'    )    )
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,       'do_center_crop'    )    )
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,       'center_crop'    )    )
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,       'do_normalize'    )    )
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,       'image_mean'    )    )
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,       'image_std'    )    )





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





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							int							=     self.image_processing_class.from_dict(self.image_processor_dict    )
					self.assertEqual(image_processor.size     ,       {'height': 20, 'width': 20}    )
					self.assertEqual(image_processor.crop_size     ,       {'height': 18, 'width': 18}    )
					self.assertEqual(image_processor.do_reduce_labels     ,       _SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							List[Any]							=     self.image_processing_class.from_dict(
					    self.image_processor_dict     ,       size=42     ,       crop_size=84     ,       reduce_labels=_SCREAMING_SNAKE_CASE    )
					self.assertEqual(image_processor.size     ,       {'height': 42, 'width': 42}    )
					self.assertEqual(image_processor.crop_size     ,       {'height': 84, 'width': 84}    )
					self.assertEqual(image_processor.do_reduce_labels     ,       _SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       str    )						->	Dict:





					"""simple docstring"""


					pass





	def 			_lowerCAmelCase     (      self				:       Any    )						->	List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     self.image_processing_class(**self.image_processor_dict    )
					# create random PIL images
					SCREAMING_SNAKE_CASE						:							List[str]							=     prepare_image_inputs(self.image_processor_tester     ,       equal_resolution=_SCREAMING_SNAKE_CASE    )
					for image in image_inputs:
									self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,       Image.Image    )

					# Test not batched input
					SCREAMING_SNAKE_CASE						:							Any							=     image_processing(image_inputs[0]     ,       return_tensors='pt'    ).pixel_values
					self.assertEqual(
					    encoded_images.shape     ,       (
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )

					# Test batched
					SCREAMING_SNAKE_CASE						:							str							=     image_processing(_SCREAMING_SNAKE_CASE     ,       return_tensors='pt'    ).pixel_values
					self.assertEqual(
					    encoded_images.shape     ,       (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )





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





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							List[str]							=     self.image_processing_class(**self.image_processor_dict    )
					# create random numpy tensors
					SCREAMING_SNAKE_CASE						:							Dict							=     prepare_image_inputs(self.image_processor_tester     ,       equal_resolution=_SCREAMING_SNAKE_CASE     ,       numpify=_SCREAMING_SNAKE_CASE    )
					for image in image_inputs:
									self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,       np.ndarray    )

					# Test not batched input
					SCREAMING_SNAKE_CASE						:							Dict							=     image_processing(image_inputs[0]     ,       return_tensors='pt'    ).pixel_values
					self.assertEqual(
					    encoded_images.shape     ,       (
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )

					# Test batched
					SCREAMING_SNAKE_CASE						:							str							=     image_processing(_SCREAMING_SNAKE_CASE     ,       return_tensors='pt'    ).pixel_values
					self.assertEqual(
					    encoded_images.shape     ,       (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )





	def 			_lowerCAmelCase     (      self				:       str    )						->	List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Any							=     self.image_processing_class(**self.image_processor_dict    )
					# create random PyTorch tensors
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     prepare_image_inputs(self.image_processor_tester     ,       equal_resolution=_SCREAMING_SNAKE_CASE     ,       torchify=_SCREAMING_SNAKE_CASE    )
					for image in image_inputs:
									self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,       torch.Tensor    )

					# Test not batched input
					SCREAMING_SNAKE_CASE						:							List[str]							=     image_processing(image_inputs[0]     ,       return_tensors='pt'    ).pixel_values
					self.assertEqual(
					    encoded_images.shape     ,       (
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )

					# Test batched
					SCREAMING_SNAKE_CASE						:							str							=     image_processing(_SCREAMING_SNAKE_CASE     ,       return_tensors='pt'    ).pixel_values
					self.assertEqual(
					    encoded_images.shape     ,       (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )





	def 			_lowerCAmelCase     (      self				:       int    )						->	Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Dict							=     self.image_processing_class(**self.image_processor_dict    )
					# create random PyTorch tensors
					SCREAMING_SNAKE_CASE						:							str							=     prepare_image_inputs(self.image_processor_tester     ,       equal_resolution=_SCREAMING_SNAKE_CASE     ,       torchify=_SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							Tuple							=     []
					for image in image_inputs:
									self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,       torch.Tensor    )
									maps.append(torch.zeros(image.shape[-2:]    ).long()    )

					# Test not batched input
					SCREAMING_SNAKE_CASE						:							int							=     image_processing(image_inputs[0]     ,       maps[0]     ,       return_tensors='pt'    )
					self.assertEqual(
					    encoding['pixel_values'].shape     ,       (
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )
					self.assertEqual(
					    encoding['labels'].shape     ,       (
					        1,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )
					self.assertEqual(encoding['labels'].dtype     ,       torch.long    )
					self.assertTrue(encoding['labels'].min().item() >= 0    )
					self.assertTrue(encoding['labels'].max().item() <= 255    )

					# Test batched
					SCREAMING_SNAKE_CASE						:							List[str]							=     image_processing(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       return_tensors='pt'    )
					self.assertEqual(
					    encoding['pixel_values'].shape     ,       (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )
					self.assertEqual(
					    encoding['labels'].shape     ,       (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )
					self.assertEqual(encoding['labels'].dtype     ,       torch.long    )
					self.assertTrue(encoding['labels'].min().item() >= 0    )
					self.assertTrue(encoding['labels'].max().item() <= 255    )

					# Test not batched input (PIL images)
					SCREAMING_SNAKE_CASE				,						SCREAMING_SNAKE_CASE						:							str							=     prepare_semantic_single_inputs()

					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     image_processing(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       return_tensors='pt'    )
					self.assertEqual(
					    encoding['pixel_values'].shape     ,       (
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )
					self.assertEqual(
					    encoding['labels'].shape     ,       (
					        1,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )
					self.assertEqual(encoding['labels'].dtype     ,       torch.long    )
					self.assertTrue(encoding['labels'].min().item() >= 0    )
					self.assertTrue(encoding['labels'].max().item() <= 255    )

					# Test batched input (PIL images)
					SCREAMING_SNAKE_CASE				,						SCREAMING_SNAKE_CASE						:							int							=     prepare_semantic_batch_inputs()

					SCREAMING_SNAKE_CASE						:							Any							=     image_processing(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       return_tensors='pt'    )
					self.assertEqual(
					    encoding['pixel_values'].shape     ,       (
					        2,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )
					self.assertEqual(
					    encoding['labels'].shape     ,       (
					        2,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )     ,       )
					self.assertEqual(encoding['labels'].dtype     ,       torch.long    )
					self.assertTrue(encoding['labels'].min().item() >= 0    )
					self.assertTrue(encoding['labels'].max().item() <= 255    )







	def 			_lowerCAmelCase     (      self				:       Optional[int]    )						->	Union[str, Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     self.image_processing_class(**self.image_processor_dict    )

					# ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
					SCREAMING_SNAKE_CASE				,						SCREAMING_SNAKE_CASE						:							Any							=     prepare_semantic_single_inputs()
					SCREAMING_SNAKE_CASE						:							int							=     image_processing(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       return_tensors='pt'    )
					self.assertTrue(encoding['labels'].min().item() >= 0    )
					self.assertTrue(encoding['labels'].max().item() <= 150    )

					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     True
					SCREAMING_SNAKE_CASE						:							Any							=     image_processing(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       return_tensors='pt'    )
					self.assertTrue(encoding['labels'].min().item() >= 0    )
					self.assertTrue(encoding['labels'].max().item() <= 255    )





