import os
import tempfile
import unittest

import numpy as np

from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax, slow


if is_flax_available():
    import jax
    import jax.numpy as jnp
    from flax.jax_utils import replicate
    from flax.training.common_utils import shard

    from diffusers import FlaxDDIMScheduler, FlaxDiffusionPipeline, FlaxStableDiffusionPipeline


@require_flax
class 			lowerCamelCase_  (     unittest.TestCase				):






    '''simple docstring'''






    def     UpperCamelCase__     (			self) ->			List[str]:
        with tempfile.TemporaryDirectory() as tmpdirname:
            # pipeline has Flax weights
            __UpperCamelCase  :Optional[Any]    						=	FlaxDiffusionPipeline.from_pretrained(
                '''hf-internal-testing/tiny-stable-diffusion-pipe'''				,				safety_checker=__lowercase				,				cache_dir=__lowercase)

            __UpperCamelCase  :List[str]    						=	[t[-1] for t in os.walk(os.path.join(__lowercase				,				os.listdir(__lowercase)[0]				,				'''snapshots'''))]
            __UpperCamelCase  :Tuple    						=	[item for sublist in all_root_files for item in sublist]

            # None of the downloaded files should be a PyTorch file even if we have some here:
            # https://huggingface.co/hf-internal-testing/tiny-stable-diffusion-pipe/blob/main/unet/diffusion_pytorch_model.bin
            assert not any(f.endswith('''.bin''') for f in files)


@slow
@require_flax
class 			lowerCamelCase_  (     unittest.TestCase				):






    '''simple docstring'''






    def     UpperCamelCase__     (			self) ->			List[Any]:
        __UpperCamelCase						, __UpperCamelCase  :Optional[int]    						=	FlaxStableDiffusionPipeline.from_pretrained(
            '''hf-internal-testing/tiny-stable-diffusion-pipe'''				,				safety_checker=__lowercase)

        __UpperCamelCase  :Union[str, Any]    						=	(
            '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
            ''' field, close up, split lighting, cinematic'''
        )

        __UpperCamelCase  :str    						=	jax.random.PRNGKey(0)
        __UpperCamelCase  :Optional[int]    						=	4

        __UpperCamelCase  :Any    						=	jax.device_count()
        __UpperCamelCase  :List[Any]    						=	num_samples * [prompt]
        __UpperCamelCase  :Optional[Any]    						=	pipeline.prepare_inputs(__lowercase)

        # shard inputs and rng
        __UpperCamelCase  :Optional[int]    						=	replicate(__lowercase)
        __UpperCamelCase  :Tuple    						=	jax.random.split(__lowercase				,				__lowercase)
        __UpperCamelCase  :Tuple    						=	shard(__lowercase)

        __UpperCamelCase  :Dict    						=	pipeline(__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				jit=__lowercase).images

        assert images.shape == (num_samples, 1, 64, 64, 3)
        if jax.device_count() == 8:
            assert np.abs(np.abs(images[0, 0, :2, :2, -2:]				,				dtype=np.floataa).sum() - 4.1_51_47_45) < 1E-3
            assert np.abs(np.abs(__lowercase				,				dtype=np.floataa).sum() - 4_99_47.8_75) < 5E-1

        __UpperCamelCase  :Tuple    						=	pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:])))
        assert len(__lowercase) == num_samples







    def     UpperCamelCase__     (			self) ->			str:
        __UpperCamelCase						, __UpperCamelCase  :List[Any]    						=	FlaxStableDiffusionPipeline.from_pretrained(
            '''CompVis/stable-diffusion-v1-4'''				,				revision='''flax'''				,				safety_checker=__lowercase)

        __UpperCamelCase  :str    						=	(
            '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
            ''' field, close up, split lighting, cinematic'''
        )

        __UpperCamelCase  :str    						=	jax.random.PRNGKey(0)
        __UpperCamelCase  :Any    						=	50

        __UpperCamelCase  :int    						=	jax.device_count()
        __UpperCamelCase  :List[Any]    						=	num_samples * [prompt]
        __UpperCamelCase  :int    						=	pipeline.prepare_inputs(__lowercase)

        # shard inputs and rng
        __UpperCamelCase  :Any    						=	replicate(__lowercase)
        __UpperCamelCase  :Dict    						=	jax.random.split(__lowercase				,				__lowercase)
        __UpperCamelCase  :str    						=	shard(__lowercase)

        __UpperCamelCase  :str    						=	pipeline(__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				jit=__lowercase).images

        assert images.shape == (num_samples, 1, 512, 512, 3)
        if jax.device_count() == 8:
            assert np.abs((np.abs(images[0, 0, :2, :2, -2:]				,				dtype=np.floataa).sum() - 0.05_65_24_01)) < 1E-3
            assert np.abs((np.abs(__lowercase				,				dtype=np.floataa).sum() - 2_38_38_08.2)) < 5E-1







    def     UpperCamelCase__     (			self) ->			List[Any]:
        __UpperCamelCase						, __UpperCamelCase  :Union[str, Any]    						=	FlaxStableDiffusionPipeline.from_pretrained(
            '''CompVis/stable-diffusion-v1-4'''				,				revision='''bf16'''				,				dtype=jnp.bfloataa				,				safety_checker=__lowercase)

        __UpperCamelCase  :int    						=	(
            '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
            ''' field, close up, split lighting, cinematic'''
        )

        __UpperCamelCase  :Optional[int]    						=	jax.random.PRNGKey(0)
        __UpperCamelCase  :List[str]    						=	50

        __UpperCamelCase  :str    						=	jax.device_count()
        __UpperCamelCase  :Optional[int]    						=	num_samples * [prompt]
        __UpperCamelCase  :int    						=	pipeline.prepare_inputs(__lowercase)

        # shard inputs and rng
        __UpperCamelCase  :List[str]    						=	replicate(__lowercase)
        __UpperCamelCase  :Tuple    						=	jax.random.split(__lowercase				,				__lowercase)
        __UpperCamelCase  :Any    						=	shard(__lowercase)

        __UpperCamelCase  :Dict    						=	pipeline(__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				jit=__lowercase).images

        assert images.shape == (num_samples, 1, 512, 512, 3)
        if jax.device_count() == 8:
            assert np.abs((np.abs(images[0, 0, :2, :2, -2:]				,				dtype=np.floataa).sum() - 0.04_00_39_06)) < 1E-3
            assert np.abs((np.abs(__lowercase				,				dtype=np.floataa).sum() - 2_37_35_16.75)) < 5E-1







    def     UpperCamelCase__     (			self) ->			Tuple:
        __UpperCamelCase						, __UpperCamelCase  :Union[str, Any]    						=	FlaxStableDiffusionPipeline.from_pretrained(
            '''CompVis/stable-diffusion-v1-4'''				,				revision='''bf16'''				,				dtype=jnp.bfloataa)

        __UpperCamelCase  :Dict    						=	(
            '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
            ''' field, close up, split lighting, cinematic'''
        )

        __UpperCamelCase  :Any    						=	jax.random.PRNGKey(0)
        __UpperCamelCase  :List[str]    						=	50

        __UpperCamelCase  :Union[str, Any]    						=	jax.device_count()
        __UpperCamelCase  :Dict    						=	num_samples * [prompt]
        __UpperCamelCase  :Union[str, Any]    						=	pipeline.prepare_inputs(__lowercase)

        # shard inputs and rng
        __UpperCamelCase  :Tuple    						=	replicate(__lowercase)
        __UpperCamelCase  :Optional[int]    						=	jax.random.split(__lowercase				,				__lowercase)
        __UpperCamelCase  :List[str]    						=	shard(__lowercase)

        __UpperCamelCase  :Optional[int]    						=	pipeline(__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				jit=__lowercase).images

        assert images.shape == (num_samples, 1, 512, 512, 3)
        if jax.device_count() == 8:
            assert np.abs((np.abs(images[0, 0, :2, :2, -2:]				,				dtype=np.floataa).sum() - 0.04_00_39_06)) < 1E-3
            assert np.abs((np.abs(__lowercase				,				dtype=np.floataa).sum() - 2_37_35_16.75)) < 5E-1







    def     UpperCamelCase__     (			self) ->			str:
        __UpperCamelCase  :Dict    						=	FlaxDDIMScheduler(
            beta_start=0.0_00_85				,				beta_end=0.0_12				,				beta_schedule='''scaled_linear'''				,				set_alpha_to_one=__lowercase				,				steps_offset=1				,				)

        __UpperCamelCase						, __UpperCamelCase  :List[str]    						=	FlaxStableDiffusionPipeline.from_pretrained(
            '''CompVis/stable-diffusion-v1-4'''				,				revision='''bf16'''				,				dtype=jnp.bfloataa				,				scheduler=__lowercase				,				safety_checker=__lowercase				,				)
        __UpperCamelCase  :List[Any]    						=	scheduler.create_state()

        __UpperCamelCase  :int    						=	scheduler_state

        __UpperCamelCase  :List[Any]    						=	(
            '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
            ''' field, close up, split lighting, cinematic'''
        )

        __UpperCamelCase  :Union[str, Any]    						=	jax.random.PRNGKey(0)
        __UpperCamelCase  :int    						=	50

        __UpperCamelCase  :List[Any]    						=	jax.device_count()
        __UpperCamelCase  :int    						=	num_samples * [prompt]
        __UpperCamelCase  :Any    						=	pipeline.prepare_inputs(__lowercase)

        # shard inputs and rng
        __UpperCamelCase  :Optional[Any]    						=	replicate(__lowercase)
        __UpperCamelCase  :str    						=	jax.random.split(__lowercase				,				__lowercase)
        __UpperCamelCase  :Dict    						=	shard(__lowercase)

        __UpperCamelCase  :List[Any]    						=	pipeline(__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				jit=__lowercase).images

        assert images.shape == (num_samples, 1, 512, 512, 3)
        if jax.device_count() == 8:
            assert np.abs((np.abs(images[0, 0, :2, :2, -2:]				,				dtype=np.floataa).sum() - 0.0_45_04_39_45)) < 1E-3
            assert np.abs((np.abs(__lowercase				,				dtype=np.floataa).sum() - 2_34_76_93.5)) < 5E-1







    def     UpperCamelCase__     (			self) ->			Optional[int]:
        __UpperCamelCase  :List[str]    						=	(
            '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
            ''' field, close up, split lighting, cinematic'''
        )

        __UpperCamelCase  :Optional[Any]    						=	jax.device_count()
        __UpperCamelCase  :Dict    						=	num_samples * [prompt]
        __UpperCamelCase  :Dict    						=	jax.random.split(jax.random.PRNGKey(0)				,				__lowercase)

        __UpperCamelCase						, __UpperCamelCase  :Dict    						=	FlaxStableDiffusionPipeline.from_pretrained(
            '''CompVis/stable-diffusion-v1-4'''				,				revision='''bf16'''				,				dtype=jnp.bfloataa				,				safety_checker=__lowercase				,				)

        __UpperCamelCase  :Union[str, Any]    						=	replicate(__lowercase)
        __UpperCamelCase  :Optional[Any]    						=	pipeline.prepare_inputs(__lowercase)
        __UpperCamelCase  :str    						=	shard(__lowercase)
        __UpperCamelCase  :str    						=	pipeline(__lowercase				,				__lowercase				,				__lowercase				,				jit=__lowercase).images
        assert images.shape == (num_samples, 1, 512, 512, 3)
        __UpperCamelCase  :Any    						=	images[2, 0, 256, 10:17, 1]

        # With memory efficient attention
        __UpperCamelCase						, __UpperCamelCase  :Optional[Any]    						=	FlaxStableDiffusionPipeline.from_pretrained(
            '''CompVis/stable-diffusion-v1-4'''				,				revision='''bf16'''				,				dtype=jnp.bfloataa				,				safety_checker=__lowercase				,				use_memory_efficient_attention=__lowercase				,				)

        __UpperCamelCase  :List[str]    						=	replicate(__lowercase)
        __UpperCamelCase  :Union[str, Any]    						=	pipeline.prepare_inputs(__lowercase)
        __UpperCamelCase  :List[Any]    						=	shard(__lowercase)
        __UpperCamelCase  :Union[str, Any]    						=	pipeline(__lowercase				,				__lowercase				,				__lowercase				,				jit=__lowercase).images
        assert images_eff.shape == (num_samples, 1, 512, 512, 3)
        __UpperCamelCase  :Optional[int]    						=	images[2, 0, 256, 10:17, 1]

        # I checked the results visually and they are very similar. However, I saw that the max diff is `1` and the `sum`
        # over the 8 images is exactly `256`, which is very suspicious. Testing a random slice for now.
        assert abs(slice_eff - slice).max() < 1E-2






import unittest

from transformers import MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING, is_vision_available, 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_  :






        '''simple docstring'''






        @staticmethod
        def     UpperCamelCase__     (			*__lowercase				,				**__lowercase) ->			Dict:
            pass


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






    '''simple docstring'''






    a__			:		str      			=   MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase) ->			str:
        __UpperCamelCase  :Union[str, Any]    						=	pipeline(
            '''zero-shot-object-detection'''				,				model='''hf-internal-testing/tiny-random-owlvit-object-detection''')

        __UpperCamelCase  :Dict    						=	[
            {
                '''image''': '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
                '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
            }
        ]
        return object_detector, examples







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase) ->			Optional[Any]:
        __UpperCamelCase  :Optional[Any]    						=	object_detector(examples[0]				,				threshold=0.0)

        __UpperCamelCase  :Dict    						=	len(__lowercase)
        self.assertGreater(__lowercase				,				0)
        self.assertEqual(
            __lowercase				,				[
                {
                    '''score''': ANY(__lowercase),
                    '''label''': ANY(__lowercase),
                    '''box''': {'''xmin''': ANY(__lowercase), '''ymin''': ANY(__lowercase), '''xmax''': ANY(__lowercase), '''ymax''': ANY(__lowercase)},
                }
                for i in range(__lowercase)
            ]				,				)







    @require_tf
    @unittest.skip('''Zero Shot Object Detection not implemented in TF''')
    def     UpperCamelCase__     (			self) ->			int:
        pass







    @require_torch
    def     UpperCamelCase__     (			self) ->			Any:
        __UpperCamelCase  :Tuple    						=	pipeline(
            '''zero-shot-object-detection'''				,				model='''hf-internal-testing/tiny-random-owlvit-object-detection''')

        __UpperCamelCase  :str    						=	object_detector(
            '''./tests/fixtures/tests_samples/COCO/000000039769.png'''				,				candidate_labels=['''cat''', '''remote''', '''couch''']				,				threshold=0.64				,				)

        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                {'''score''': 0.72_35, '''label''': '''cat''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
                {'''score''': 0.72_18, '''label''': '''remote''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
                {'''score''': 0.71_84, '''label''': '''couch''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
                {'''score''': 0.67_48, '''label''': '''remote''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
                {'''score''': 0.66_56, '''label''': '''cat''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
                {'''score''': 0.66_14, '''label''': '''couch''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
                {'''score''': 0.64_56, '''label''': '''remote''', '''box''': {'''xmin''': 494, '''ymin''': 105, '''xmax''': 521, '''ymax''': 127}},
                {'''score''': 0.6_42, '''label''': '''remote''', '''box''': {'''xmin''': 67, '''ymin''': 274, '''xmax''': 93, '''ymax''': 297}},
                {'''score''': 0.64_19, '''label''': '''cat''', '''box''': {'''xmin''': 494, '''ymin''': 105, '''xmax''': 521, '''ymax''': 127}},
            ]				,				)

        __UpperCamelCase  :str    						=	object_detector(
            [
                {
                    '''image''': '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
                    '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
                }
            ]				,				threshold=0.64				,				)

        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                [
                    {'''score''': 0.72_35, '''label''': '''cat''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
                    {'''score''': 0.72_18, '''label''': '''remote''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
                    {'''score''': 0.71_84, '''label''': '''couch''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
                    {'''score''': 0.67_48, '''label''': '''remote''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
                    {'''score''': 0.66_56, '''label''': '''cat''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
                    {'''score''': 0.66_14, '''label''': '''couch''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
                    {'''score''': 0.64_56, '''label''': '''remote''', '''box''': {'''xmin''': 494, '''ymin''': 105, '''xmax''': 521, '''ymax''': 127}},
                    {'''score''': 0.6_42, '''label''': '''remote''', '''box''': {'''xmin''': 67, '''ymin''': 274, '''xmax''': 93, '''ymax''': 297}},
                    {'''score''': 0.64_19, '''label''': '''cat''', '''box''': {'''xmin''': 494, '''ymin''': 105, '''xmax''': 521, '''ymax''': 127}},
                ]
            ]				,				)







    @require_torch
    @slow
    def     UpperCamelCase__     (			self) ->			Optional[int]:
        __UpperCamelCase  :List[str]    						=	pipeline('''zero-shot-object-detection''')

        __UpperCamelCase  :List[str]    						=	object_detector(
            '''http://images.cocodataset.org/val2017/000000039769.jpg'''				,				candidate_labels=['''cat''', '''remote''', '''couch''']				,				)
        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
                {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
                {'''score''': 0.25_37, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 315, '''ymax''': 472}},
                {'''score''': 0.14_74, '''label''': '''remote''', '''box''': {'''xmin''': 335, '''ymin''': 74, '''xmax''': 371, '''ymax''': 187}},
                {'''score''': 0.12_08, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 642, '''ymax''': 476}},
            ]				,				)

        __UpperCamelCase  :Dict    						=	object_detector(
            [
                {
                    '''image''': '''http://images.cocodataset.org/val2017/000000039769.jpg''',
                    '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
                },
                {
                    '''image''': '''http://images.cocodataset.org/val2017/000000039769.jpg''',
                    '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
                },
            ]				,				)
        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                [
                    {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
                    {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
                    {'''score''': 0.25_37, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 315, '''ymax''': 472}},
                    {'''score''': 0.14_74, '''label''': '''remote''', '''box''': {'''xmin''': 335, '''ymin''': 74, '''xmax''': 371, '''ymax''': 187}},
                    {'''score''': 0.12_08, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 642, '''ymax''': 476}},
                ],
                [
                    {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
                    {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
                    {'''score''': 0.25_37, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 315, '''ymax''': 472}},
                    {'''score''': 0.14_74, '''label''': '''remote''', '''box''': {'''xmin''': 335, '''ymin''': 74, '''xmax''': 371, '''ymax''': 187}},
                    {'''score''': 0.12_08, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 642, '''ymax''': 476}},
                ],
            ]				,				)







    @require_tf
    @unittest.skip('''Zero Shot Object Detection not implemented in TF''')
    def     UpperCamelCase__     (			self) ->			Dict:
        pass







    @require_torch
    @slow
    def     UpperCamelCase__     (			self) ->			str:
        __UpperCamelCase  :Tuple    						=	0.2
        __UpperCamelCase  :str    						=	pipeline('''zero-shot-object-detection''')

        __UpperCamelCase  :Any    						=	object_detector(
            '''http://images.cocodataset.org/val2017/000000039769.jpg'''				,				candidate_labels=['''cat''', '''remote''', '''couch''']				,				threshold=__lowercase				,				)
        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
                {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
                {'''score''': 0.25_37, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 315, '''ymax''': 472}},
            ]				,				)







    @require_torch
    @slow
    def     UpperCamelCase__     (			self) ->			Any:
        __UpperCamelCase  :Optional[int]    						=	2
        __UpperCamelCase  :Union[str, Any]    						=	pipeline('''zero-shot-object-detection''')

        __UpperCamelCase  :Any    						=	object_detector(
            '''http://images.cocodataset.org/val2017/000000039769.jpg'''				,				candidate_labels=['''cat''', '''remote''', '''couch''']				,				top_k=__lowercase				,				)
        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
                {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
            ]				,				)





