





import gc
import random
import unittest

import numpy as np
import torch
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModelWithProjection,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import (
    DiffusionPipeline,
    UnCLIPImageVariationPipeline,
    UnCLIPScheduler,
    UNetaDConditionModel,
    UNetaDModel,
)
from diffusers.pipelines.unclip.text_proj import UnCLIPTextProjModel
from diffusers.utils import floats_tensor, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, load_image, require_torch_gpu, skip_mps

from ..pipeline_params import IMAGE_VARIATION_BATCH_PARAMS, IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()





class 						_A(					snake_case__				, unittest.TestCase   ):


				"""simple docstring"""


				UpperCamelCase    :  Optional[Any]					    =	UnCLIPImageVariationPipeline
				UpperCamelCase    :  Optional[Any]					    =	IMAGE_VARIATION_PARAMS - {'''height''', '''width''', '''guidance_scale'''}
				UpperCamelCase    :  Optional[int]					    =	IMAGE_VARIATION_BATCH_PARAMS

				UpperCamelCase    :  List[Any]					    =	[
				    '''generator''',
				    '''return_dict''',
				    '''decoder_num_inference_steps''',
				    '''super_res_num_inference_steps''',
				]
				UpperCamelCase    :  Optional[int]					    =	False



				@property
				def 					UpperCAmelCase_		(			self     ):
									return 32



				@property
				def 					UpperCAmelCase_		(			self     ):
									return 32



				@property
				def 					UpperCAmelCase_		(			self     ):
									return self.time_input_dim



				@property
				def 					UpperCAmelCase_		(			self     ):
									return self.time_input_dim * 4



				@property
				def 					UpperCAmelCase_		(			self     ):
									return 100



				@property
				def 					UpperCAmelCase_		(			self     ):
									__A	:						List[str]       =				CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'     )
									return tokenizer



				@property
				def 					UpperCAmelCase_		(			self     ):
									torch.manual_seed(0     )
									__A	:						str       =				CLIPTextConfig(
									    bos_token_id=0     ,					eos_token_id=2     ,					hidden_size=self.text_embedder_hidden_size     ,					projection_dim=self.text_embedder_hidden_size     ,					intermediate_size=37     ,					layer_norm_eps=1e-0_5     ,					num_attention_heads=4     ,					num_hidden_layers=5     ,					pad_token_id=1     ,					vocab_size=1000     ,					)
									return CLIPTextModelWithProjection(_A     )



				@property
				def 					UpperCAmelCase_		(			self     ):
									torch.manual_seed(0     )
									__A	:						Tuple       =				CLIPVisionConfig(
									    hidden_size=self.text_embedder_hidden_size     ,					projection_dim=self.text_embedder_hidden_size     ,					num_hidden_layers=5     ,					num_attention_heads=4     ,					image_size=32     ,					intermediate_size=37     ,					patch_size=1     ,					)
									return CLIPVisionModelWithProjection(_A     )



				@property
				def 					UpperCAmelCase_		(			self     ):
									torch.manual_seed(0     )

									__A	:						Optional[int]       =				{
									    'clip_embeddings_dim': self.text_embedder_hidden_size,
									    'time_embed_dim': self.time_embed_dim,
									    'cross_attention_dim': self.cross_attention_dim,
									}

									__A	:						Tuple       =				UnCLIPTextProjModel(**_A     )
									return model



				@property
				def 					UpperCAmelCase_		(			self     ):
									torch.manual_seed(0     )

									__A	:						Optional[int]       =				{
									    'sample_size': 32,
									    # RGB in channels
									    'in_channels': 3,
									    # Out channels is double in channels because predicts mean and variance
									    'out_channels': 6,
									    'down_block_types': ('ResnetDownsampleBlock2D', 'SimpleCrossAttnDownBlock2D'),
									    'up_block_types': ('SimpleCrossAttnUpBlock2D', 'ResnetUpsampleBlock2D'),
									    'mid_block_type': 'UNetMidBlock2DSimpleCrossAttn',
									    'block_out_channels': (self.block_out_channels_a, self.block_out_channels_a * 2),
									    'layers_per_block': 1,
									    'cross_attention_dim': self.cross_attention_dim,
									    'attention_head_dim': 4,
									    'resnet_time_scale_shift': 'scale_shift',
									    'class_embed_type': 'identity',
									}

									__A	:						Optional[Any]       =				UNetaDConditionModel(**_A     )
									return model



				@property
				def 					UpperCAmelCase_		(			self     ):
									return {
									    "sample_size": 64,
									    "layers_per_block": 1,
									    "down_block_types": ("ResnetDownsampleBlock2D", "ResnetDownsampleBlock2D"),
									    "up_block_types": ("ResnetUpsampleBlock2D", "ResnetUpsampleBlock2D"),
									    "block_out_channels": (self.block_out_channels_a, self.block_out_channels_a * 2),
									    "in_channels": 6,
									    "out_channels": 3,
									}



				@property
				def 					UpperCAmelCase_		(			self     ):
									torch.manual_seed(0     )

									__A	:						Any       =				UNetaDModel(**self.dummy_super_res_kwargs     )
									return model



				@property
				def 					UpperCAmelCase_		(			self     ):
									# seeded differently to get different unet than `self.dummy_super_res_first`
									torch.manual_seed(1     )

									__A	:						Optional[Any]       =				UNetaDModel(**self.dummy_super_res_kwargs     )
									return model



				def 					UpperCAmelCase_		(			self     ):
									__A	:						Optional[Any]       =				self.dummy_decoder
									__A	:						int       =				self.dummy_text_proj
									__A	:						Dict       =				self.dummy_text_encoder
									__A	:						Optional[int]       =				self.dummy_tokenizer
									__A	:						Tuple       =				self.dummy_super_res_first
									__A	:						Union[str, Any]       =				self.dummy_super_res_last

									__A	:						Any       =				UnCLIPScheduler(
									    variance_type='learned_range'     ,					prediction_type='epsilon'     ,					num_train_timesteps=1000     ,					)

									__A	:						Any       =				UnCLIPScheduler(
									    variance_type='fixed_small_log'     ,					prediction_type='epsilon'     ,					num_train_timesteps=1000     ,					)

									__A	:						Union[str, Any]       =				CLIPImageProcessor(crop_size=32     ,					size=32     )

									__A	:						int       =				self.dummy_image_encoder

									return {
									    "decoder": decoder,
									    "text_encoder": text_encoder,
									    "tokenizer": tokenizer,
									    "text_proj": text_proj,
									    "feature_extractor": feature_extractor,
									    "image_encoder": image_encoder,
									    "super_res_first": super_res_first,
									    "super_res_last": super_res_last,
									    "decoder_scheduler": decoder_scheduler,
									    "super_res_scheduler": super_res_scheduler,
									}



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A=0     ,					_A=True     ):
									__A	:						Tuple       =				floats_tensor((1, 3, 32, 32)     ,					rng=random.Random(_A     )     ).to(_A     )
									if str(_A     ).startswith('mps'     ):
														__A	:						Dict       =				torch.manual_seed(_A     )
									else:
														__A	:						List[Any]       =				torch.Generator(device=_A     ).manual_seed(_A     )

									if pil_image:
														__A	:						Tuple       =				input_image * 0.5 + 0.5
														__A	:						Union[str, Any]       =				input_image.clamp(0     ,					1     )
														__A	:						Any       =				input_image.cpu().permute(0     ,					2     ,					3     ,					1     ).float().numpy()
														__A	:						List[Any]       =				DiffusionPipeline.numpy_to_pil(_A     )[0]

									return {
									    "image": input_image,
									    "generator": generator,
									    "decoder_num_inference_steps": 2,
									    "super_res_num_inference_steps": 2,
									    "output_type": "np",
									}



				def 					UpperCAmelCase_		(			self     ):
									__A	:						Any       =				'cpu'

									__A	:						Tuple       =				self.get_dummy_components()

									__A	:						Tuple       =				self.pipeline_class(**_A     )
									__A	:						Tuple       =				pipe.to(_A     )

									pipe.set_progress_bar_config(disable=_A     )

									__A	:						Optional[int]       =				self.get_dummy_inputs(_A     ,					pil_image=_A     )

									__A	:						Dict       =				pipe(**_A     )
									__A	:						Tuple       =				output.images

									__A	:						Union[str, Any]       =				self.get_dummy_inputs(_A     ,					pil_image=_A     )

									__A	:						int       =				pipe(
									    **_A     ,					return_dict=_A     ,					)[0]

									__A	:						Optional[Any]       =				image[0, -3:, -3:, -1]
									__A	:						Dict       =				image_from_tuple[0, -3:, -3:, -1]

									assert image.shape == (1, 64, 64, 3)

									__A	:						Dict       =				np.array(
									    [
									        0.9_9_9_7,
									        0.0_0_0_2,
									        0.9_9_9_7,
									        0.9_9_9_7,
									        0.9_9_6_9,
									        0.0_0_2_3,
									        0.9_9_9_7,
									        0.9_9_6_9,
									        0.9_9_7_0,
									    ]     )

									assert np.abs(image_slice.flatten() - expected_slice     ).max() < 1e-2
									assert np.abs(image_from_tuple_slice.flatten() - expected_slice     ).max() < 1e-2



				def 					UpperCAmelCase_		(			self     ):
									__A	:						Optional[int]       =				'cpu'

									__A	:						List[Any]       =				self.get_dummy_components()

									__A	:						Optional[Any]       =				self.pipeline_class(**_A     )
									__A	:						List[str]       =				pipe.to(_A     )

									pipe.set_progress_bar_config(disable=_A     )

									__A	:						List[str]       =				self.get_dummy_inputs(_A     ,					pil_image=_A     )

									__A	:						List[str]       =				pipe(**_A     )
									__A	:						Optional[Any]       =				output.images

									__A	:						Optional[int]       =				self.get_dummy_inputs(_A     ,					pil_image=_A     )

									__A	:						Dict       =				pipe(
									    **_A     ,					return_dict=_A     ,					)[0]

									__A	:						Optional[Any]       =				image[0, -3:, -3:, -1]
									__A	:						str       =				image_from_tuple[0, -3:, -3:, -1]

									assert image.shape == (1, 64, 64, 3)

									__A	:						Tuple       =				np.array([0.9_9_9_7, 0.0_0_0_3, 0.9_9_9_7, 0.9_9_9_7, 0.9_9_7_0, 0.0_0_2_4, 0.9_9_9_7, 0.9_9_7_1, 0.9_9_7_1]     )

									assert np.abs(image_slice.flatten() - expected_slice     ).max() < 1e-2
									assert np.abs(image_from_tuple_slice.flatten() - expected_slice     ).max() < 1e-2



				def 					UpperCAmelCase_		(			self     ):
									__A	:						Optional[int]       =				'cpu'

									__A	:						str       =				self.get_dummy_components()

									__A	:						List[str]       =				self.pipeline_class(**_A     )
									__A	:						Dict       =				pipe.to(_A     )

									pipe.set_progress_bar_config(disable=_A     )

									__A	:						List[str]       =				self.get_dummy_inputs(_A     ,					pil_image=_A     )
									__A	:						Union[str, Any]       =				[
									    pipeline_inputs['image'],
									    pipeline_inputs['image'],
									]

									__A	:						Optional[int]       =				pipe(**_A     )
									__A	:						Tuple       =				output.images

									__A	:						Dict       =				self.get_dummy_inputs(_A     ,					pil_image=_A     )
									__A	:						Any       =				[
									    tuple_pipeline_inputs['image'],
									    tuple_pipeline_inputs['image'],
									]

									__A	:						Union[str, Any]       =				pipe(
									    **_A     ,					return_dict=_A     ,					)[0]

									__A	:						List[Any]       =				image[0, -3:, -3:, -1]
									__A	:						str       =				image_from_tuple[0, -3:, -3:, -1]

									assert image.shape == (2, 64, 64, 3)

									__A	:						Any       =				np.array(
									    [
									        0.9_9_9_7,
									        0.9_9_8_9,
									        0.0_0_0_8,
									        0.0_0_2_1,
									        0.9_9_6_0,
									        0.0_0_1_8,
									        0.0_0_1_4,
									        0.0_0_0_2,
									        0.9_9_3_3,
									    ]     )

									assert np.abs(image_slice.flatten() - expected_slice     ).max() < 1e-2
									assert np.abs(image_from_tuple_slice.flatten() - expected_slice     ).max() < 1e-2



				def 					UpperCAmelCase_		(			self     ):
									__A	:						Tuple       =				torch.device('cpu'     )





									class 						_A:


													"""simple docstring"""


													UpperCamelCase    :  List[Any]					    =	1




									__A	:						str       =				self.get_dummy_components()

									__A	:						Optional[int]       =				self.pipeline_class(**_A     )
									__A	:						Tuple       =				pipe.to(_A     )

									pipe.set_progress_bar_config(disable=_A     )

									__A	:						Optional[int]       =				torch.Generator(device=_A     ).manual_seed(0     )
									__A	:						List[str]       =				pipe.decoder.dtype
									__A	:						List[Any]       =				1

									__A	:						Optional[int]       =				(
									    batch_size,
									    pipe.decoder.config.in_channels,
									    pipe.decoder.config.sample_size,
									    pipe.decoder.config.sample_size,
									)
									__A	:						Any       =				pipe.prepare_latents(
									    _A     ,					dtype=_A     ,					device=_A     ,					generator=_A     ,					latents=_A     ,					scheduler=DummyScheduler()     )

									__A	:						Tuple       =				(
									    batch_size,
									    pipe.super_res_first.config.in_channels // 2,
									    pipe.super_res_first.config.sample_size,
									    pipe.super_res_first.config.sample_size,
									)
									__A	:						Tuple       =				pipe.prepare_latents(
									    _A     ,					dtype=_A     ,					device=_A     ,					generator=_A     ,					latents=_A     ,					scheduler=DummyScheduler()     )

									__A	:						Optional[int]       =				self.get_dummy_inputs(_A     ,					pil_image=_A     )

									__A	:						Dict       =				pipe(
									    **_A     ,					decoder_latents=_A     ,					super_res_latents=_A     ).images

									__A	:						int       =				self.get_dummy_inputs(_A     ,					pil_image=_A     )
									# Don't pass image, instead pass embedding
									__A	:						Any       =				pipeline_inputs.pop('image'     )
									__A	:						List[str]       =				pipe.image_encoder(_A     ).image_embeds

									__A	:						List[str]       =				pipe(
									    **_A     ,					decoder_latents=_A     ,					super_res_latents=_A     ,					image_embeddings=_A     ,					).images

									# make sure passing text embeddings manually is identical
									assert np.abs(img_out_a - img_out_a     ).max() < 1e-4



				@skip_mps
				def 					UpperCAmelCase_		(			self     ):
									__A	:						str       =				torch_device == 'cpu'

									# Check is relaxed because there is not a torch 2.0 sliced attention added kv processor
									__A	:						Tuple       =				1e-2

									self._test_attention_slicing_forward_pass(
									    test_max_difference=_A     ,					expected_max_diff=_A     )



				@skip_mps
				def 					UpperCAmelCase_		(			self     ):
									__A	:						Union[str, Any]       =				torch_device == 'cpu'
									__A	:						List[Any]       =				True
									__A	:						Dict       =				[
									    'decoder_num_inference_steps',
									    'super_res_num_inference_steps',
									]

									self._test_inference_batch_single_identical(
									    test_max_difference=_A     ,					relax_max_difference=_A     ,					additional_params_copy_to_batched_inputs=_A     ,					)



				def 					UpperCAmelCase_		(			self     ):
									__A	:						Union[str, Any]       =				[
									    'decoder_num_inference_steps',
									    'super_res_num_inference_steps',
									]

									if torch_device == "mps":
														# TODO: MPS errors with larger batch sizes
														__A	:						Any       =				[2, 3]
														self._test_inference_batch_consistent(
														    batch_sizes=_A     ,					additional_params_copy_to_batched_inputs=_A     ,					)
									else:
														self._test_inference_batch_consistent(
														    additional_params_copy_to_batched_inputs=_A     )



				@skip_mps
				def 					UpperCAmelCase_		(			self     ):
									return super().test_dict_tuple_outputs_equivalent()



				@skip_mps
				def 					UpperCAmelCase_		(			self     ):
									return super().test_save_load_local()





				@skip_mps
				def 					UpperCAmelCase_		(			self     ):
									return super().test_save_load_optional_components()





@slow
@require_torch_gpu
class 						_A(					unittest.TestCase   ):


				"""simple docstring"""


				def 					UpperCAmelCase_		(			self     ):
									# clean up the VRAM after each test
									super().tearDown()
									gc.collect()
									torch.cuda.empty_cache()





				def 					UpperCAmelCase_		(			self     ):
									__A	:						Tuple       =				load_image(
									    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/unclip/cat.png'     )
									__A	:						Dict       =				load_numpy(
									    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
									    '/unclip/karlo_v1_alpha_cat_variation_fp16.npy'     )

									__A	:						Optional[Any]       =				UnCLIPImageVariationPipeline.from_pretrained(
									    'kakaobrain/karlo-v1-alpha-image-variations'     ,					torch_dtype=torch.floataa     )
									__A	:						Tuple       =				pipeline.to(_A     )
									pipeline.set_progress_bar_config(disable=_A     )

									__A	:						Optional[Any]       =				torch.Generator(device='cpu'     ).manual_seed(0     )
									__A	:						List[Any]       =				pipeline(
									    _A     ,					generator=_A     ,					output_type='np'     ,					)

									__A	:						Optional[Any]       =				output.images[0]

									assert image.shape == (256, 256, 3)

									assert_mean_pixel_difference(_A     ,					_A     ,					15     )











import hashlib
import unittest
from typing import Dict

import numpy as np

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


if is_vision_available():
				from PIL import Image
else:





				class 						_A:


								"""simple docstring"""


								@staticmethod
								def 					UpperCAmelCase_		(			*_A     ,					**_A     ):
													pass







def  _SCREAMING_SNAKE_CASE				(   a  )      ->      str:
					__A	:						str       =				hashlib.mda(image.tobytes()  )
					return m.hexdigest()[:10]







def  _SCREAMING_SNAKE_CASE				(   a  )      ->      Dict:
					__A	:						Dict       =				np.array(a  )
					__A	:						List[Any]       =				npimg.shape
					return {"hash": hashimage(a  ), "shape": shape}





@is_pipeline_test
@require_vision
@require_torch
class 						_A(					unittest.TestCase   ):


				"""simple docstring"""


				UpperCamelCase    :  str					    =	dict(
				    (list(MODEL_FOR_MASK_GENERATION_MAPPING.items()   ) if MODEL_FOR_MASK_GENERATION_MAPPING else [])   )
				UpperCamelCase    :  int					    =	dict(
				    (list(TF_MODEL_FOR_MASK_GENERATION_MAPPING.items()   ) if TF_MODEL_FOR_MASK_GENERATION_MAPPING else [])   )



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ,					_A     ):
									__A	:						Dict       =				MaskGenerationPipeline(model=_A     ,					image_processor=_A     )
									return image_segmenter, [
									    "./tests/fixtures/tests_samples/COCO/000000039769.png",
									    "./tests/fixtures/tests_samples/COCO/000000039769.png",
									]



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ):
									pass



				@require_tf
				@unittest.skip('Image segmentation not implemented in TF'     )
				def 					UpperCAmelCase_		(			self     ):
									pass



				@slow
				@require_torch
				def 					UpperCAmelCase_		(			self     ):
									__A	:						Union[str, Any]       =				pipeline('mask-generation'     ,					model='facebook/sam-vit-huge'     )

									__A	:						List[str]       =				image_segmenter('http://images.cocodataset.org/val2017/000000039769.jpg'     ,					points_per_batch=256     )

									# Shortening by hashing
									__A	:						List[Any]       =				[]
									for i, o in enumerate(outputs['masks']     ):
														new_outupt += [{"mask": mask_to_test_readable(_A     ), "scores": outputs["scores"][i]}]

									# fmt: off
									self.assertEqual(
									    nested_simplify(_A     ,					decimals=4     )     ,					[
									        {'mask': {'hash': '115ad19f5f', 'shape': (480, 640)}, 'scores': 1.0_4_4_4},
									        {'mask': {'hash': '6affa964c6', 'shape': (480, 640)}, 'scores': 1.0_2_1},
									        {'mask': {'hash': 'dfe28a0388', 'shape': (480, 640)}, 'scores': 1.0_1_6_7},
									        {'mask': {'hash': 'c0a5f4a318', 'shape': (480, 640)}, 'scores': 1.0_1_3_2},
									        {'mask': {'hash': 'fe8065c197', 'shape': (480, 640)}, 'scores': 1.0_0_5_3},
									        {'mask': {'hash': 'e2d0b7a0b7', 'shape': (480, 640)}, 'scores': 0.9_9_6_7},
									        {'mask': {'hash': '453c7844bd', 'shape': (480, 640)}, 'scores': 0.9_9_3},
									        {'mask': {'hash': '3d44f2926d', 'shape': (480, 640)}, 'scores': 0.9_9_0_9},
									        {'mask': {'hash': '64033ddc3f', 'shape': (480, 640)}, 'scores': 0.9_8_7_9},
									        {'mask': {'hash': '801064ff79', 'shape': (480, 640)}, 'scores': 0.9_8_3_4},
									        {'mask': {'hash': '6172f276ef', 'shape': (480, 640)}, 'scores': 0.9_7_1_6},
									        {'mask': {'hash': 'b49e60e084', 'shape': (480, 640)}, 'scores': 0.9_6_1_2},
									        {'mask': {'hash': 'a811e775fd', 'shape': (480, 640)}, 'scores': 0.9_5_9_9},
									        {'mask': {'hash': 'a6a8ebcf4b', 'shape': (480, 640)}, 'scores': 0.9_5_5_2},
									        {'mask': {'hash': '9d8257e080', 'shape': (480, 640)}, 'scores': 0.9_5_3_2},
									        {'mask': {'hash': '32de6454a8', 'shape': (480, 640)}, 'scores': 0.9_5_1_6},
									        {'mask': {'hash': 'af3d4af2c8', 'shape': (480, 640)}, 'scores': 0.9_4_9_9},
									        {'mask': {'hash': '3c6db475fb', 'shape': (480, 640)}, 'scores': 0.9_4_8_3},
									        {'mask': {'hash': 'c290813fb9', 'shape': (480, 640)}, 'scores': 0.9_4_6_4},
									        {'mask': {'hash': 'b6f0b8f606', 'shape': (480, 640)}, 'scores': 0.9_4_3},
									        {'mask': {'hash': '92ce16bfdf', 'shape': (480, 640)}, 'scores': 0.9_4_3},
									        {'mask': {'hash': 'c749b25868', 'shape': (480, 640)}, 'scores': 0.9_4_0_8},
									        {'mask': {'hash': 'efb6cab859', 'shape': (480, 640)}, 'scores': 0.9_3_3_5},
									        {'mask': {'hash': '1ff2eafb30', 'shape': (480, 640)}, 'scores': 0.9_3_2_6},
									        {'mask': {'hash': '788b798e24', 'shape': (480, 640)}, 'scores': 0.9_2_6_2},
									        {'mask': {'hash': 'abea804f0e', 'shape': (480, 640)}, 'scores': 0.8_9_9_9},
									        {'mask': {'hash': '7b9e8ddb73', 'shape': (480, 640)}, 'scores': 0.8_9_8_6},
									        {'mask': {'hash': 'cd24047c8a', 'shape': (480, 640)}, 'scores': 0.8_9_8_4},
									        {'mask': {'hash': '6943e6bcbd', 'shape': (480, 640)}, 'scores': 0.8_8_7_3},
									        {'mask': {'hash': 'b5f47c9191', 'shape': (480, 640)}, 'scores': 0.8_8_7_1}
									    ]     ,					)
									# fmt: on





				@require_torch
				@slow
				def 					UpperCAmelCase_		(			self     ):
									__A	:						Optional[Any]       =				'facebook/sam-vit-huge'
									__A	:						List[str]       =				pipeline('mask-generation'     ,					model=_A     )

									__A	:						Tuple       =				image_segmenter(
									    'http://images.cocodataset.org/val2017/000000039769.jpg'     ,					pred_iou_thresh=1     ,					points_per_batch=256     )

									# Shortening by hashing
									__A	:						List[str]       =				[]
									for i, o in enumerate(outputs['masks']     ):
														new_outupt += [{"mask": mask_to_test_readable(_A     ), "scores": outputs["scores"][i]}]

									self.assertEqual(
									    nested_simplify(_A     ,					decimals=4     )     ,					[
									        {'mask': {'hash': '115ad19f5f', 'shape': (480, 640)}, 'scores': 1.0_4_4_4},
									        {'mask': {'hash': '6affa964c6', 'shape': (480, 640)}, 'scores': 1.0_2_1_0},
									        {'mask': {'hash': 'dfe28a0388', 'shape': (480, 640)}, 'scores': 1.0_1_6_7},
									        {'mask': {'hash': 'c0a5f4a318', 'shape': (480, 640)}, 'scores': 1.0_1_3_2},
									        {'mask': {'hash': 'fe8065c197', 'shape': (480, 640)}, 'scores': 1.0_0_5_3},
									    ]     ,					)




