



import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
							import torch

							from transformers import (
							    MODEL_MAPPING,
							    SegformerForImageClassification,
							    SegformerForSemanticSegmentation,
							    SegformerModel,
							)
							from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import SegformerImageProcessor







class     __lowerCAmelCase					(    A		):



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



						"""simple docstring"""






						_UpperCAmelCase	 =     self.config_class(**self.inputs_dict)
						self.parent.assertTrue(hasattr(A				,	'hidden_sizes'))
						self.parent.assertTrue(hasattr(A				,	'num_attention_heads'))
						self.parent.assertTrue(hasattr(A				,	'num_encoder_blocks'))







class     __lowerCAmelCase					:



			def __init__(		self     :						Optional[Any]				,	A     :						Dict				,	A     :						List[str]=13				,	A     :						Any=64				,	A     :						Dict=3				,	A     :						Union[str, Any]=4				,	A     :						Optional[int]=[2, 2, 2, 2]				,	A     :						Tuple=[8, 4, 2, 1]				,	A     :						Union[str, Any]=[16, 32, 64, 1_28]				,	A     :						str=[1, 4, 8, 16]				,	A     :						List[str]=[1, 2, 4, 8]				,	A     :						Tuple=True				,	A     :						str=True				,	A     :						int="gelu"				,	A     :						int=0.1				,	A     :						List[Any]=0.1				,	A     :						Dict=0.0_2				,	A     :						str=3				,	A     :						Dict=None				,	)     ->					Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase	 =     parent
						_UpperCAmelCase	 =     batch_size
						_UpperCAmelCase	 =     image_size
						_UpperCAmelCase	 =     num_channels
						_UpperCAmelCase	 =     num_encoder_blocks
						_UpperCAmelCase	 =     sr_ratios
						_UpperCAmelCase	 =     depths
						_UpperCAmelCase	 =     hidden_sizes
						_UpperCAmelCase	 =     downsampling_rates
						_UpperCAmelCase	 =     num_attention_heads
						_UpperCAmelCase	 =     is_training
						_UpperCAmelCase	 =     use_labels
						_UpperCAmelCase	 =     hidden_act
						_UpperCAmelCase	 =     hidden_dropout_prob
						_UpperCAmelCase	 =     attention_probs_dropout_prob
						_UpperCAmelCase	 =     initializer_range
						_UpperCAmelCase	 =     num_labels
						_UpperCAmelCase	 =     scope



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



						"""simple docstring"""






						_UpperCAmelCase	 =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

						_UpperCAmelCase	 =     None
						if self.use_labels:
									_UpperCAmelCase	 =     ids_tensor([self.batch_size, self.image_size, self.image_size]				,	self.num_labels)

						_UpperCAmelCase	 =     self.get_config()
						return config, pixel_values, labels



			def 					_lowerCamelCase (		self     :						Dict)     ->					str:



						"""simple docstring"""






						return SegformerConfig(
						    image_size=self.image_size				,	num_channels=self.num_channels				,	num_encoder_blocks=self.num_encoder_blocks				,	depths=self.depths				,	hidden_sizes=self.hidden_sizes				,	num_attention_heads=self.num_attention_heads				,	hidden_act=self.hidden_act				,	hidden_dropout_prob=self.hidden_dropout_prob				,	attention_probs_dropout_prob=self.attention_probs_dropout_prob				,	initializer_range=self.initializer_range				,	)



			def 					_lowerCamelCase (		self     :						Tuple				,	A     :						Union[str, Any]				,	A     :						str				,	A     :						int)     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     SegformerModel(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(A)
						_UpperCAmelCase	 =     _UpperCAmelCase	 =     self.image_size // (self.downsampling_rates[-1] * 2)
						self.parent.assertEqual(
						    result.last_hidden_state.shape				,	(self.batch_size, self.hidden_sizes[-1], expected_height, expected_width))



			def 					_lowerCamelCase (		self     :						Any				,	A     :						Dict				,	A     :						int				,	A     :						Optional[Any])     ->					Union[str, Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.num_labels
						_UpperCAmelCase	 =     SegformerForSemanticSegmentation(A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(A)
						self.parent.assertEqual(
						    result.logits.shape				,	(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4))
						_UpperCAmelCase	 =     model(A				,	labels=A)
						self.parent.assertEqual(
						    result.logits.shape				,	(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4))
						self.parent.assertGreater(result.loss				,	0.0)



			def 					_lowerCamelCase (		self     :						Optional[Any]				,	A     :						Optional[Any]				,	A     :						Dict				,	A     :						Tuple)     ->					str:



						"""simple docstring"""






						_UpperCAmelCase	 =     1
						_UpperCAmelCase	 =     SegformerForSemanticSegmentation(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     torch.randint(0				,	1				,	(self.batch_size, self.image_size, self.image_size)).to(A)
						_UpperCAmelCase	 =     model(A				,	labels=A)
						self.parent.assertGreater(result.loss				,	0.0)



			def 					_lowerCamelCase (		self     :						Any)     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.prepare_config_and_inputs()
						_UpperCAmelCase ,  _UpperCAmelCase ,  _UpperCAmelCase	 =     config_and_inputs
						_UpperCAmelCase	 =     {'pixel_values': pixel_values}
						return config, inputs_dict







@require_torch
class     __lowerCAmelCase					(    A       ,		A       ,		unittest.TestCase		):
			UpperCamelCase           =  (
			    (
			        SegformerModel,
			        SegformerForSemanticSegmentation,
			        SegformerForImageClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			UpperCamelCase           =  (
			    {
			        '''feature-extraction''': SegformerModel,
			        '''image-classification''': SegformerForImageClassification,
			        '''image-segmentation''': SegformerForSemanticSegmentation,
			    }
			    if is_torch_available()
			    else {}
			)

			UpperCamelCase           =  True
			UpperCamelCase           =  False
			UpperCamelCase           =  False
			UpperCamelCase           =  False



			def 					_lowerCamelCase (		self     :						Optional[int])     ->					str:



						"""simple docstring"""






						_UpperCAmelCase	 =     SegformerModelTester(self)
						_UpperCAmelCase	 =     SegformerConfigTester(self				,	config_class=A)



			def 					_lowerCamelCase (		self     :						str)     ->					str:



						"""simple docstring"""






						self.config_tester.run_common_tests()



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



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*A)



			def 					_lowerCamelCase (		self     :						Tuple)     ->					List[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_binary_image_segmentation(*A)



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



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_segmentation(*A)



			@unittest.skip('SegFormer does not use inputs_embeds')
			def 					_lowerCamelCase (		self     :						Union[str, Any])     ->					Optional[int]:



						"""simple docstring"""






						pass



			@unittest.skip('SegFormer does not have get_input_embeddings method and get_output_embeddings methods')
			def 					_lowerCamelCase (		self     :						Union[str, Any])     ->					str:



						"""simple docstring"""






						pass



			def 					_lowerCamelCase (		self     :						int)     ->					Dict:



						"""simple docstring"""






						_UpperCAmelCase ,  _UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									_UpperCAmelCase	 =     model_class(A)
									_UpperCAmelCase	 =     inspect.signature(model.forward)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									_UpperCAmelCase	 =     [*signature.parameters.keys()]

									_UpperCAmelCase	 =     ['pixel_values']
									self.assertListEqual(arg_names[:1]				,	A)



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



						"""simple docstring"""






						_UpperCAmelCase ,  _UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs_for_common()
						_UpperCAmelCase	 =     True

						for model_class in self.all_model_classes:
									_UpperCAmelCase	 =     True
									_UpperCAmelCase	 =     False
									_UpperCAmelCase	 =     True
									_UpperCAmelCase	 =     model_class(A)
									model.to(A)
									model.eval()
									with torch.no_grad():
												_UpperCAmelCase	 =     model(**self._prepare_for_class(A				,	A))
									_UpperCAmelCase	 =     outputs.attentions

									_UpperCAmelCase	 =     sum(self.model_tester.depths)
									self.assertEqual(len(A)				,	A)

									# check that output_attentions also work using config
									del inputs_dict["output_attentions"]
									_UpperCAmelCase	 =     True
									_UpperCAmelCase	 =     model_class(A)
									model.to(A)
									model.eval()
									with torch.no_grad():
												_UpperCAmelCase	 =     model(**self._prepare_for_class(A				,	A))
									_UpperCAmelCase	 =     outputs.attentions

									self.assertEqual(len(A)				,	A)

									# verify the first attentions (first block, first layer)
									_UpperCAmelCase	 =     (self.model_tester.image_size // 4) ** 2
									_UpperCAmelCase	 =     (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
									self.assertListEqual(
									    list(attentions[0].shape[-3:])				,	[self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]				,	)

									# verify the last attentions (last block, last layer)
									_UpperCAmelCase	 =     (self.model_tester.image_size // 32) ** 2
									_UpperCAmelCase	 =     (self.model_tester.image_size // (32 * self.model_tester.sr_ratios[-1])) ** 2
									self.assertListEqual(
									    list(attentions[-1].shape[-3:])				,	[self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]				,	)
									_UpperCAmelCase	 =     len(A)

									# Check attention is always last and order is fine
									_UpperCAmelCase	 =     True
									_UpperCAmelCase	 =     True
									_UpperCAmelCase	 =     model_class(A)
									model.to(A)
									model.eval()
									with torch.no_grad():
												_UpperCAmelCase	 =     model(**self._prepare_for_class(A				,	A))

									self.assertEqual(out_len + 1				,	len(A))

									_UpperCAmelCase	 =     outputs.attentions

									self.assertEqual(len(A)				,	A)
									# verify the first attentions (first block, first layer)
									_UpperCAmelCase	 =     (self.model_tester.image_size // 4) ** 2
									_UpperCAmelCase	 =     (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
									self.assertListEqual(
									    list(self_attentions[0].shape[-3:])				,	[self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]				,	)



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



						"""simple docstring"""






						def check_hidden_states_output(A     :						str				,	A     :						List[Any]				,	A     :						str):
									_UpperCAmelCase	 =     model_class(A)
									model.to(A)
									model.eval()

									with torch.no_grad():
												_UpperCAmelCase	 =     model(**self._prepare_for_class(A				,	A))

									_UpperCAmelCase	 =     outputs.hidden_states

									_UpperCAmelCase	 =     self.model_tester.num_encoder_blocks
									self.assertEqual(len(A)				,	A)

									# verify the first hidden states (first block)
									self.assertListEqual(
									    list(hidden_states[0].shape[-3:])				,	[
									        self.model_tester.hidden_sizes[0],
									        self.model_tester.image_size // 4,
									        self.model_tester.image_size // 4,
									    ]				,	)

						_UpperCAmelCase ,  _UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									_UpperCAmelCase	 =     True
									check_hidden_states_output(A				,	A				,	A)

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									_UpperCAmelCase	 =     True

									check_hidden_states_output(A				,	A				,	A)



			def 					_lowerCamelCase (		self     :						str)     ->					Optional[int]:



						"""simple docstring"""






						if not self.model_tester.is_training:
									return

						_UpperCAmelCase ,  _UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs_for_common()
						_UpperCAmelCase	 =     True

						for model_class in self.all_model_classes:
									if model_class in get_values(A):
												continue

									_UpperCAmelCase	 =     model_class(A)
									model.to(A)
									model.train()
									_UpperCAmelCase	 =     self._prepare_for_class(A				,	A				,	return_labels=A)
									_UpperCAmelCase	 =     model(**A).loss
									loss.backward()



			@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.')
			def 					_lowerCamelCase (		self     :						Union[str, Any])     ->					Union[str, Any]:



						"""simple docstring"""






						pass



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



						"""simple docstring"""






						for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_UpperCAmelCase	 =     SegformerModel.from_pretrained(A)
									self.assertIsNotNone(A)





def 							A			(  )       ->				int:







			'''simple docstring'''
			_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'					)
			return image







@require_torch
class     __lowerCAmelCase					(    unittest.TestCase		):



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



						"""simple docstring"""






						_UpperCAmelCase	 =     SegformerImageProcessor(
						    image_scale=(5_12, 5_12)				,	keep_ratio=A				,	align=A				,	do_random_crop=A)
						_UpperCAmelCase	 =     SegformerForSemanticSegmentation.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512').to(
						    A)

						_UpperCAmelCase	 =     prepare_img()
						_UpperCAmelCase	 =     image_processor(images=A				,	return_tensors='pt')
						_UpperCAmelCase	 =     encoded_inputs.pixel_values.to(A)

						with torch.no_grad():
									_UpperCAmelCase	 =     model(A)

						_UpperCAmelCase	 =     torch.Size((1, model.config.num_labels, 1_28, 1_28))
						self.assertEqual(outputs.logits.shape				,	A)

						_UpperCAmelCase	 =     torch.tensor(
						    [
						        [[-4.6_3_1_0, -5.5_2_3_2, -6.2_3_5_6], [-5.1_9_2_1, -6.1_4_4_4, -6.5_9_9_6], [-5.4_4_2_4, -6.2_7_9_0, -6.7_5_7_4]],
						        [[-1_2.1_3_9_1, -1_3.3_1_2_2, -1_3.9_5_5_4], [-1_2.8_7_3_2, -1_3.9_3_5_2, -1_4.3_5_6_3], [-1_2.9_4_3_8, -1_3.8_2_2_6, -1_4.2_5_1_3]],
						        [[-1_2.5_1_3_4, -1_3.4_6_8_6, -1_4.4_9_1_5], [-1_2.8_6_6_9, -1_4.4_3_4_3, -1_4.7_7_5_8], [-1_3.2_5_2_3, -1_4.5_8_1_9, -1_5.0_6_9_4]],
						    ]).to(A)
						self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]				,	A				,	atol=1E-4))



			@slow
			def 					_lowerCamelCase (		self     :						Union[str, Any])     ->					Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase	 =     SegformerImageProcessor(
						    image_scale=(5_12, 5_12)				,	keep_ratio=A				,	align=A				,	do_random_crop=A)
						_UpperCAmelCase	 =     SegformerForSemanticSegmentation.from_pretrained(
						    'nvidia/segformer-b1-finetuned-cityscapes-1024-1024').to(A)

						_UpperCAmelCase	 =     prepare_img()
						_UpperCAmelCase	 =     image_processor(images=A				,	return_tensors='pt')
						_UpperCAmelCase	 =     encoded_inputs.pixel_values.to(A)

						with torch.no_grad():
									_UpperCAmelCase	 =     model(A)

						_UpperCAmelCase	 =     torch.Size((1, model.config.num_labels, 1_28, 1_28))
						self.assertEqual(outputs.logits.shape				,	A)

						_UpperCAmelCase	 =     torch.tensor(
						    [
						        [[-1_3.5_7_4_8, -1_3.9_1_1_1, -1_2.6_5_0_0], [-1_4.3_5_0_0, -1_5.3_6_8_3, -1_4.2_3_2_8], [-1_4.7_5_3_2, -1_6.0_4_2_4, -1_5.6_0_8_7]],
						        [[-1_7.1_6_5_1, -1_5.8_7_2_5, -1_2.9_6_5_3], [-1_7.2_5_8_0, -1_7.3_7_1_8, -1_4.8_2_2_3], [-1_6.6_0_5_8, -1_6.8_7_8_3, -1_6.7_4_5_2]],
						        [[-3.6_4_5_6, -3.0_2_0_9, -1.4_2_0_3], [-3.0_7_9_7, -3.1_9_5_9, -2.0_0_0_0], [-1.8_7_5_7, -1.9_2_1_7, -1.6_9_9_7]],
						    ]).to(A)
						self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]				,	A				,	atol=1E-1))



			@slow
			def 					_lowerCamelCase (		self     :						Dict)     ->					Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     SegformerImageProcessor(
						    image_scale=(5_12, 5_12)				,	keep_ratio=A				,	align=A				,	do_random_crop=A)
						_UpperCAmelCase	 =     SegformerForSemanticSegmentation.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512').to(
						    A)

						_UpperCAmelCase	 =     prepare_img()
						_UpperCAmelCase	 =     image_processor(images=A				,	return_tensors='pt')
						_UpperCAmelCase	 =     encoded_inputs.pixel_values.to(A)

						with torch.no_grad():
									_UpperCAmelCase	 =     model(A)

						_UpperCAmelCase	 =     outputs.logits.detach().cpu()

						_UpperCAmelCase	 =     image_processor.post_process_semantic_segmentation(outputs=A				,	target_sizes=[(5_00, 3_00)])
						_UpperCAmelCase	 =     torch.Size((5_00, 3_00))
						self.assertEqual(segmentation[0].shape				,	A)

						_UpperCAmelCase	 =     image_processor.post_process_semantic_segmentation(outputs=A)
						_UpperCAmelCase	 =     torch.Size((1_28, 1_28))
						self.assertEqual(segmentation[0].shape				,	A)





import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
							from PIL import Image
else:







							class     __lowerCAmelCase					:



										@staticmethod
										def 					_lowerCamelCase (		*A     :						Union[str, Any]				,	**A     :						List[Any])     ->					Union[str, Any]:



													"""simple docstring"""






													pass







@is_pipeline_test
@require_vision
class     __lowerCAmelCase					(    unittest.TestCase		):



			@require_torch
			def 					_lowerCamelCase (		self     :						List[str])     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     pipeline(
						    model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'				,	)
						_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
						_UpperCAmelCase	 =     image_classifier(A				,	candidate_labels=['a', 'b', 'c'])

						# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
						# python and torch versions.
						self.assertIn(
						    nested_simplify(A)				,	[
						        [{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'b'}, {'score': 0.3_3_3, 'label': 'c'}],
						        [{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'c'}, {'score': 0.3_3_3, 'label': 'b'}],
						    ]				,	)

						_UpperCAmelCase	 =     image_classifier([image] * 5				,	candidate_labels=['A', 'B', 'C']				,	batch_size=2)
						self.assertEqual(
						    nested_simplify(A)				,	[
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						    ]				,	)



			@require_tf
			def 					_lowerCamelCase (		self     :						str)     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     pipeline(
						    model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'				,	framework='tf')
						_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
						_UpperCAmelCase	 =     image_classifier(A				,	candidate_labels=['a', 'b', 'c'])

						self.assertEqual(
						    nested_simplify(A)				,	[{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'b'}, {'score': 0.3_3_3, 'label': 'c'}]				,	)

						_UpperCAmelCase	 =     image_classifier([image] * 5				,	candidate_labels=['A', 'B', 'C']				,	batch_size=2)
						self.assertEqual(
						    nested_simplify(A)				,	[
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						    ]				,	)



			@slow
			@require_torch
			def 					_lowerCamelCase (		self     :						Tuple)     ->					Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     pipeline(
						    task='zero-shot-image-classification'				,	model='openai/clip-vit-base-patch32'				,	)
						# This is an image of 2 cats with remotes and no planes
						_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
						_UpperCAmelCase	 =     image_classifier(A				,	candidate_labels=['cat', 'plane', 'remote'])

						self.assertEqual(
						    nested_simplify(A)				,	[
						        {'score': 0.5_1_1, 'label': 'remote'},
						        {'score': 0.4_8_5, 'label': 'cat'},
						        {'score': 0.0_0_4, 'label': 'plane'},
						    ]				,	)

						_UpperCAmelCase	 =     image_classifier([image] * 5				,	candidate_labels=['cat', 'plane', 'remote']				,	batch_size=2)
						self.assertEqual(
						    nested_simplify(A)				,	[
						        [
						            {'score': 0.5_1_1, 'label': 'remote'},
						            {'score': 0.4_8_5, 'label': 'cat'},
						            {'score': 0.0_0_4, 'label': 'plane'},
						        ],
						    ]
						    * 5				,	)



			@slow
			@require_tf
			def 					_lowerCamelCase (		self     :						List[str])     ->					Any:



						"""simple docstring"""






						_UpperCAmelCase	 =     pipeline(
						    task='zero-shot-image-classification'				,	model='openai/clip-vit-base-patch32'				,	framework='tf')
						# This is an image of 2 cats with remotes and no planes
						_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
						_UpperCAmelCase	 =     image_classifier(A				,	candidate_labels=['cat', 'plane', 'remote'])
						self.assertEqual(
						    nested_simplify(A)				,	[
						        {'score': 0.5_1_1, 'label': 'remote'},
						        {'score': 0.4_8_5, 'label': 'cat'},
						        {'score': 0.0_0_4, 'label': 'plane'},
						    ]				,	)

						_UpperCAmelCase	 =     image_classifier([image] * 5				,	candidate_labels=['cat', 'plane', 'remote']				,	batch_size=2)
						self.assertEqual(
						    nested_simplify(A)				,	[
						        [
						            {'score': 0.5_1_1, 'label': 'remote'},
						            {'score': 0.4_8_5, 'label': 'cat'},
						            {'score': 0.0_0_4, 'label': 'plane'},
						        ],
						    ]
						    * 5				,	)
