



import gc
import unittest

from transformers import CTRLConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, 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 (
     CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
     CTRLForSequenceClassification,
     CTRLLMHeadModel,
     CTRLModel,
 )

class 					_A :



       def __init__(	self							:  Optional[Any]  ,	__SCREAMING_SNAKE_CASE							:  Any  ,	__SCREAMING_SNAKE_CASE							:  int=14  ,	__SCREAMING_SNAKE_CASE							:  str=7  ,	__SCREAMING_SNAKE_CASE							:  Optional[int]=True  ,	__SCREAMING_SNAKE_CASE							:  Tuple=True  ,	__SCREAMING_SNAKE_CASE							:  Dict=True  ,	__SCREAMING_SNAKE_CASE							:  Tuple=True  ,	__SCREAMING_SNAKE_CASE							:  Tuple=True  ,	__SCREAMING_SNAKE_CASE							:  Any=99  ,	__SCREAMING_SNAKE_CASE							:  Any=32  ,	__SCREAMING_SNAKE_CASE							:  List[Any]=5  ,	__SCREAMING_SNAKE_CASE							:  Optional[int]=4  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]=37  ,	__SCREAMING_SNAKE_CASE							:  Any="gelu"  ,	__SCREAMING_SNAKE_CASE							:  Tuple=0.1  ,	__SCREAMING_SNAKE_CASE							:  Tuple=0.1  ,	__SCREAMING_SNAKE_CASE							:  Tuple=512  ,	__SCREAMING_SNAKE_CASE							:  Dict=16  ,	__SCREAMING_SNAKE_CASE							:  Union[str, Any]=2  ,	__SCREAMING_SNAKE_CASE							:  int=0.02  ,	__SCREAMING_SNAKE_CASE							:  Dict=3  ,	__SCREAMING_SNAKE_CASE							:  Tuple=4  ,	__SCREAMING_SNAKE_CASE							:  int=None  ,	):


           '''simple docstring'''

           __a		 =       parent
           __a		 =       batch_size
           __a		 =       seq_length
           __a		 =       is_training
           __a		 =       use_token_type_ids
           __a		 =       use_input_mask
           __a		 =       use_labels
           __a		 =       use_mc_token_ids
           __a		 =       vocab_size
           __a		 =       hidden_size
           __a		 =       num_hidden_layers
           __a		 =       num_attention_heads
           __a		 =       intermediate_size
           __a		 =       hidden_act
           __a		 =       hidden_dropout_prob
           __a		 =       attention_probs_dropout_prob
           __a		 =       max_position_embeddings
           __a		 =       type_vocab_size
           __a		 =       type_sequence_label_size
           __a		 =       initializer_range
           __a		 =       num_labels
           __a		 =       num_choices
           __a		 =       scope
           __a		 =       self.vocab_size - 1



       def 	_lowerCamelCase    (	self							:  Dict):


           '''simple docstring'''

           __a		 =       ids_tensor([self.batch_size, self.seq_length]  ,	self.vocab_size)

           __a		 =       None
           if self.use_input_mask:
               __a		 =       random_attention_mask([self.batch_size, self.seq_length])

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

           __a		 =       None
           if self.use_mc_token_ids:
               __a		 =       ids_tensor([self.batch_size, self.num_choices]  ,	self.seq_length)

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

           __a		 =       self.get_config()

           __a		 =       ids_tensor([self.num_hidden_layers, self.num_attention_heads]  ,	2)

           return (
               config,
               input_ids,
               input_mask,
               head_mask,
               token_type_ids,
               mc_token_ids,
               sequence_labels,
               token_labels,
               choice_labels,
           )



       def 	_lowerCamelCase    (	self							:  List[Any]):


           '''simple docstring'''

           return CTRLConfig(
               vocab_size=self.vocab_size  ,	n_embd=self.hidden_size  ,	n_layer=self.num_hidden_layers  ,	n_head=self.num_attention_heads  ,	n_positions=self.max_position_embeddings  ,	pad_token_id=self.pad_token_id  ,	)



       def 	_lowerCamelCase    (	self							:  str  ,	__SCREAMING_SNAKE_CASE							:  int  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]  ,	__SCREAMING_SNAKE_CASE							:  Dict  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]  ,	*__SCREAMING_SNAKE_CASE							:  Optional[int]):


           '''simple docstring'''

           __a		 =       CTRLModel(config=lowercase_)
           model.to(lowercase_)
           model.eval()

           model(lowercase_  ,	token_type_ids=lowercase_  ,	head_mask=lowercase_)
           model(lowercase_  ,	token_type_ids=lowercase_)
           __a		 =       model(lowercase_)
           self.parent.assertEqual(result.last_hidden_state.shape  ,	(self.batch_size, self.seq_length, self.hidden_size))
           self.parent.assertEqual(len(result.past_key_values)  ,	config.n_layer)



       def 	_lowerCamelCase    (	self							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]  ,	__SCREAMING_SNAKE_CASE							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  int  ,	*__SCREAMING_SNAKE_CASE							:  List[Any]):


           '''simple docstring'''

           __a		 =       CTRLLMHeadModel(lowercase_)
           model.to(lowercase_)
           model.eval()

           __a		 =       model(lowercase_  ,	token_type_ids=lowercase_  ,	labels=lowercase_)
           self.parent.assertEqual(result.loss.shape  ,	())
           self.parent.assertEqual(result.logits.shape  ,	(self.batch_size, self.seq_length, self.vocab_size))



       def 	_lowerCamelCase    (	self							:  Optional[int]):


           '''simple docstring'''

           __a		 =       self.prepare_config_and_inputs()

           (
               __a 
           )		 =       config_and_inputs

           __a		 =       {"input_ids": input_ids, "token_type_ids": token_type_ids, "head_mask": head_mask}

           return config, inputs_dict





       def 	_lowerCamelCase    (	self							:  Optional[Any]  ,	__SCREAMING_SNAKE_CASE							:  Dict  ,	__SCREAMING_SNAKE_CASE							:  int  ,	__SCREAMING_SNAKE_CASE							:  Tuple  ,	__SCREAMING_SNAKE_CASE							:  int  ,	*__SCREAMING_SNAKE_CASE							:  List[Any]):


           '''simple docstring'''

           __a		 =       self.num_labels
           __a		 =       CTRLForSequenceClassification(lowercase_)
           model.to(lowercase_)
           model.eval()
           __a		 =       ids_tensor([self.batch_size]  ,	self.type_sequence_label_size)
           __a		 =       model(lowercase_  ,	token_type_ids=lowercase_  ,	labels=lowercase_)
           self.parent.assertEqual(result.logits.shape  ,	(self.batch_size, self.num_labels))


@require_torch
class 					_A (			snake_case__   ,snake_case__   ,snake_case__   ,unittest.TestCase					):
       UpperCamelCase__						:					Optional[int]		      =		(CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
       UpperCamelCase__						:					Tuple		      =		(CTRLLMHeadModel,) if is_torch_available() else ()
       UpperCamelCase__						:					Dict		      =		(
           {
               '''feature-extraction''': CTRLModel,
               '''text-classification''': CTRLForSequenceClassification,
               '''text-generation''': CTRLLMHeadModel,
               '''zero-shot''': CTRLForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )
       UpperCamelCase__						:					Dict		      =		True
       UpperCamelCase__						:					List[Any]		      =		False
       UpperCamelCase__						:					int		      =		False



       def 	_lowerCamelCase    (	self							:  Tuple  ,	__SCREAMING_SNAKE_CASE							:  int  ,	__SCREAMING_SNAKE_CASE							:  Union[str, Any]  ,	__SCREAMING_SNAKE_CASE							:  Tuple  ,	__SCREAMING_SNAKE_CASE							:  Optional[int]  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]):


           '''simple docstring'''

           if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
               # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
               # `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
               # config could not be created.
               return True

           return False



       def 	_lowerCamelCase    (	self							:  List[Any]):


           '''simple docstring'''

           __a		 =       CTRLModelTester(self)
           __a		 =       ConfigTester(self  ,	config_class=lowercase_  ,	n_embd=37)



       def 	_lowerCamelCase    (	self							:  Dict):


           '''simple docstring'''

           super().tearDown()
           # clean-up as much as possible GPU memory occupied by PyTorch
           gc.collect()
           torch.cuda.empty_cache()



       def 	_lowerCamelCase    (	self							:  Any):


           '''simple docstring'''

           self.config_tester.run_common_tests()



       def 	_lowerCamelCase    (	self							:  Optional[Any]):


           '''simple docstring'''

           __a		 =       self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_ctrl_model(*lowercase_)



       def 	_lowerCamelCase    (	self							:  List[Any]):


           '''simple docstring'''

           __a		 =       self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_lm_head_model(*lowercase_)



       @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.''')
       def 	_lowerCamelCase    (	self							:  str):


           '''simple docstring'''

           pass



       @slow
       def 	_lowerCamelCase    (	self							:  Optional[int]):


           '''simple docstring'''

           for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __a		 =       CTRLModel.from_pretrained(lowercase_)
               self.assertIsNotNone(lowercase_)





       @unittest.skip('''The model doesn\'t support left padding''')  # and it's not used enough to be worth fixing :)
       def 	_lowerCamelCase    (	self							:  Tuple):


           '''simple docstring'''

           pass


@require_torch
class 					_A (			unittest.TestCase					):



       def 	_lowerCamelCase    (	self							:  int):


           '''simple docstring'''

           super().tearDown()
           # clean-up as much as possible GPU memory occupied by PyTorch
           gc.collect()
           torch.cuda.empty_cache()





       @slow
       def 	_lowerCamelCase    (	self							:  Union[str, Any]):


           '''simple docstring'''

           __a		 =       CTRLLMHeadModel.from_pretrained('''ctrl''')
           model.to(lowercase_)
           __a		 =       torch.tensor(
               [[11_859, 0, 1_611, 8]]  ,	dtype=torch.long  ,	device=lowercase_)  # Legal the president is
           __a		 =       [
               11_859,
               0,
               1_611,
               8,
               5,
               150,
               26_449,
               2,
               19,
               348,
               469,
               3,
               2_595,
               48,
               20_740,
               246_533,
               246_533,
               19,
               30,
               5,
           ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

           __a		 =       model.generate(lowercase_  ,	do_sample=lowercase_)
           self.assertListEqual(output_ids[0].tolist()  ,	lowercase_)










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 					_A (			unittest.TestCase					):



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


           '''simple docstring'''

           __a		 =       size if size is not None else {'''height''': 20, '''width''': 20}
           __a		 =       crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
           __a		 =       parent
           __a		 =       batch_size
           __a		 =       num_channels
           __a		 =       image_size
           __a		 =       min_resolution
           __a		 =       max_resolution
           __a		 =       do_resize
           __a		 =       size
           __a		 =       do_center_crop
           __a		 =       crop_size
           __a		 =       do_normalize
           __a		 =       image_mean
           __a		 =       image_std
           __a		 =       do_reduce_labels





       def 	_lowerCamelCase    (	self							:  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			(    ):
    __a		 =       load_dataset('''hf-internal-testing/fixtures_ade20k'''     ,				split='''test'''       )

    __a		 =       Image.open(dataset[0]['''file''']       )
    __a		 =       Image.open(dataset[1]['''file''']       )

    return image, map





def   __snake_case			(    ):
    __a		 =       load_dataset('''hf-internal-testing/fixtures_ade20k'''     ,				split='''test'''       )

    __a		 =       Image.open(ds[0]['''file''']       )
    __a		 =       Image.open(ds[1]['''file''']       )
    __a		 =       Image.open(ds[2]['''file''']       )
    __a		 =       Image.open(ds[3]['''file''']       )

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

@require_torch
@require_vision
class 					_A (			__UpperCAmelCase   ,unittest.TestCase					):
       UpperCamelCase__						:					Union[str, Any]		      =		BeitImageProcessor if is_vision_available() else None



       def 	_lowerCamelCase    (	self							:  int):


           '''simple docstring'''

           __a		 =       BeitImageProcessingTester(self)



       @property
       def 	_lowerCamelCase    (	self							:  int):


           '''simple docstring'''

           return self.image_processor_tester.prepare_image_processor_dict()



       def 	_lowerCamelCase    (	self							:  Optional[Any]):


           '''simple docstring'''

           __a		 =       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							:  str):


           '''simple docstring'''

           __a		 =       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)

           __a		 =       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							:  Dict):


           '''simple docstring'''

           pass



       def 	_lowerCamelCase    (	self							:  Tuple):


           '''simple docstring'''

           __a		 =       self.image_processing_class(**self.image_processor_dict)
           # create random PIL images
           __a		 =       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
           __a		 =       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
           __a		 =       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):


           '''simple docstring'''

           __a		 =       self.image_processing_class(**self.image_processor_dict)
           # create random numpy tensors
           __a		 =       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
           __a		 =       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
           __a		 =       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							:  List[Any]):


           '''simple docstring'''

           __a		 =       self.image_processing_class(**self.image_processor_dict)
           # create random PyTorch tensors
           __a		 =       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
           __a		 =       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
           __a		 =       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							:  Dict):


           '''simple docstring'''

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

           # Test not batched input
           __a		 =       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
           __a		 =       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)
           __a ,     __a		 =       prepare_semantic_single_inputs()

           __a		 =       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)
           __a ,     __a		 =       prepare_semantic_batch_inputs()

           __a		 =       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							:  Dict):


           '''simple docstring'''

           __a		 =       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
           __a ,     __a		 =       prepare_semantic_single_inputs()
           __a		 =       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)

           __a		 =       True
           __a		 =       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)





