




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     snake_case__							:
						"""simple docstring"""



						@staticmethod
						def 							__UpperCAmelCase							(      *__lowerCamelCase				:     int					,      **__lowerCamelCase				:     Optional[int]							)					->     Dict:
									pass




@is_pipeline_test
@require_vision
@require_torch
class     snake_case__							(unittest.TestCase   ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_       :							Optional[Any]							 =					MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING





				def 							__UpperCAmelCase							(      self				:     Any					,      __lowerCamelCase				:     Tuple					,      __lowerCamelCase				:     List[str]					,      __lowerCamelCase				:     Dict							)					->     Union[str, Any]:
							a    =			pipeline(
							    "zero-shot-object-detection"					,      model="hf-internal-testing/tiny-random-owlvit-object-detection"							)

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





				def 							__UpperCAmelCase							(      self				:     Optional[Any]					,      __lowerCamelCase				:     Dict					,      __lowerCamelCase				:     Optional[Any]							)					->     Optional[Any]:
							a    =			object_detector(examples[0]					,      threshold=0.0							)

							a    =			len(__lowerCamelCase							)
							self.assertGreater(__lowerCamelCase					,      0							)
							self.assertEqual(
							    __lowerCamelCase					,      [
							        {
							            "score": ANY(__lowerCamelCase							),
							            "label": ANY(__lowerCamelCase							),
							            "box": {"xmin": ANY(__lowerCamelCase							), "ymin": ANY(__lowerCamelCase							), "xmax": ANY(__lowerCamelCase							), "ymax": ANY(__lowerCamelCase							)},
							        }
							        for i in range(__lowerCamelCase							)
							    ]					,      )





				@require_tf
				@unittest.skip("Zero Shot Object Detection not implemented in TF"							)
				def 							__UpperCAmelCase							(      self				:     Optional[Any]							)					->     Optional[Any]:
							pass





				@require_torch
				def 							__UpperCAmelCase							(      self				:     List[Any]							)					->     Optional[Any]:
							a    =			pipeline(
							    "zero-shot-object-detection"					,      model="hf-internal-testing/tiny-random-owlvit-object-detection"							)

							a    =			object_detector(
							    "./tests/fixtures/tests_samples/COCO/000000039769.png"					,      candidate_labels=["cat", "remote", "couch"]					,      threshold=0.64					,      )

							self.assertEqual(
							    nested_simplify(__lowerCamelCase					,      decimals=4							)					,      [
							        {"score": 0.7_235, "label": "cat", "box": {"xmin": 2_04, "ymin": 1_67, "xmax": 2_32, "ymax": 1_90}},
							        {"score": 0.7_218, "label": "remote", "box": {"xmin": 2_04, "ymin": 1_67, "xmax": 2_32, "ymax": 1_90}},
							        {"score": 0.7_184, "label": "couch", "box": {"xmin": 2_04, "ymin": 1_67, "xmax": 2_32, "ymax": 1_90}},
							        {"score": 0.6_748, "label": "remote", "box": {"xmin": 5_71, "ymin": 83, "xmax": 5_98, "ymax": 1_03}},
							        {"score": 0.6_656, "label": "cat", "box": {"xmin": 5_71, "ymin": 83, "xmax": 5_98, "ymax": 1_03}},
							        {"score": 0.6_614, "label": "couch", "box": {"xmin": 5_71, "ymin": 83, "xmax": 5_98, "ymax": 1_03}},
							        {"score": 0.6_456, "label": "remote", "box": {"xmin": 4_94, "ymin": 1_05, "xmax": 5_21, "ymax": 1_27}},
							        {"score": 0.642, "label": "remote", "box": {"xmin": 67, "ymin": 2_74, "xmax": 93, "ymax": 2_97}},
							        {"score": 0.6_419, "label": "cat", "box": {"xmin": 4_94, "ymin": 1_05, "xmax": 5_21, "ymax": 1_27}},
							    ]					,      )

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

							self.assertEqual(
							    nested_simplify(__lowerCamelCase					,      decimals=4							)					,      [
							        [
							            {"score": 0.7_235, "label": "cat", "box": {"xmin": 2_04, "ymin": 1_67, "xmax": 2_32, "ymax": 1_90}},
							            {"score": 0.7_218, "label": "remote", "box": {"xmin": 2_04, "ymin": 1_67, "xmax": 2_32, "ymax": 1_90}},
							            {"score": 0.7_184, "label": "couch", "box": {"xmin": 2_04, "ymin": 1_67, "xmax": 2_32, "ymax": 1_90}},
							            {"score": 0.6_748, "label": "remote", "box": {"xmin": 5_71, "ymin": 83, "xmax": 5_98, "ymax": 1_03}},
							            {"score": 0.6_656, "label": "cat", "box": {"xmin": 5_71, "ymin": 83, "xmax": 5_98, "ymax": 1_03}},
							            {"score": 0.6_614, "label": "couch", "box": {"xmin": 5_71, "ymin": 83, "xmax": 5_98, "ymax": 1_03}},
							            {"score": 0.6_456, "label": "remote", "box": {"xmin": 4_94, "ymin": 1_05, "xmax": 5_21, "ymax": 1_27}},
							            {"score": 0.642, "label": "remote", "box": {"xmin": 67, "ymin": 2_74, "xmax": 93, "ymax": 2_97}},
							            {"score": 0.6_419, "label": "cat", "box": {"xmin": 4_94, "ymin": 1_05, "xmax": 5_21, "ymax": 1_27}},
							        ]
							    ]					,      )





				@require_torch
				@slow
				def 							__UpperCAmelCase							(      self				:     List[Any]							)					->     Dict:
							a    =			pipeline("zero-shot-object-detection"							)

							a    =			object_detector(
							    "http://images.cocodataset.org/val2017/000000039769.jpg"					,      candidate_labels=["cat", "remote", "couch"]					,      )
							self.assertEqual(
							    nested_simplify(__lowerCamelCase					,      decimals=4							)					,      [
							        {"score": 0.2_868, "label": "cat", "box": {"xmin": 3_24, "ymin": 20, "xmax": 6_40, "ymax": 3_73}},
							        {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 1_77, "ymax": 1_15}},
							        {"score": 0.2_537, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 3_15, "ymax": 4_72}},
							        {"score": 0.1_474, "label": "remote", "box": {"xmin": 3_35, "ymin": 74, "xmax": 3_71, "ymax": 1_87}},
							        {"score": 0.1_208, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 6_42, "ymax": 4_76}},
							    ]					,      )

							a    =			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(__lowerCamelCase					,      decimals=4							)					,      [
							        [
							            {"score": 0.2_868, "label": "cat", "box": {"xmin": 3_24, "ymin": 20, "xmax": 6_40, "ymax": 3_73}},
							            {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 1_77, "ymax": 1_15}},
							            {"score": 0.2_537, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 3_15, "ymax": 4_72}},
							            {"score": 0.1_474, "label": "remote", "box": {"xmin": 3_35, "ymin": 74, "xmax": 3_71, "ymax": 1_87}},
							            {"score": 0.1_208, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 6_42, "ymax": 4_76}},
							        ],
							        [
							            {"score": 0.2_868, "label": "cat", "box": {"xmin": 3_24, "ymin": 20, "xmax": 6_40, "ymax": 3_73}},
							            {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 1_77, "ymax": 1_15}},
							            {"score": 0.2_537, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 3_15, "ymax": 4_72}},
							            {"score": 0.1_474, "label": "remote", "box": {"xmin": 3_35, "ymin": 74, "xmax": 3_71, "ymax": 1_87}},
							            {"score": 0.1_208, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 6_42, "ymax": 4_76}},
							        ],
							    ]					,      )





				@require_tf
				@unittest.skip("Zero Shot Object Detection not implemented in TF"							)
				def 							__UpperCAmelCase							(      self				:     List[str]							)					->     Tuple:
							pass





				@require_torch
				@slow
				def 							__UpperCAmelCase							(      self				:     Any							)					->     Tuple:
							a    =			0.2
							a    =			pipeline("zero-shot-object-detection"							)

							a    =			object_detector(
							    "http://images.cocodataset.org/val2017/000000039769.jpg"					,      candidate_labels=["cat", "remote", "couch"]					,      threshold=__lowerCamelCase					,      )
							self.assertEqual(
							    nested_simplify(__lowerCamelCase					,      decimals=4							)					,      [
							        {"score": 0.2_868, "label": "cat", "box": {"xmin": 3_24, "ymin": 20, "xmax": 6_40, "ymax": 3_73}},
							        {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 1_77, "ymax": 1_15}},
							        {"score": 0.2_537, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 3_15, "ymax": 4_72}},
							    ]					,      )





				@require_torch
				@slow
				def 							__UpperCAmelCase							(      self				:     str							)					->     Any:
							a    =			2
							a    =			pipeline("zero-shot-object-detection"							)

							a    =			object_detector(
							    "http://images.cocodataset.org/val2017/000000039769.jpg"					,      candidate_labels=["cat", "remote", "couch"]					,      top_k=__lowerCamelCase					,      )
							self.assertEqual(
							    nested_simplify(__lowerCamelCase					,      decimals=4							)					,      [
							        {"score": 0.2_868, "label": "cat", "box": {"xmin": 3_24, "ymin": 20, "xmax": 6_40, "ymax": 3_73}},
							        {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 1_77, "ymax": 1_15}},
							    ]					,      )












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


__lowerCAmelCase		:				Optional[Any]       			=		logging.get_logger(__name__)

__lowerCAmelCase		:				str       			=		{'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/config.json'}




class     snake_case__							(_UpperCamelCase   ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_       :							Dict							 =					"""openai-gpt"""
				SCREAMING_SNAKE_CASE_       :							Tuple							 =					{
				    """max_position_embeddings""": """n_positions""",
				    """hidden_size""": """n_embd""",
				    """num_attention_heads""": """n_head""",
				    """num_hidden_layers""": """n_layer""",
				}





				def __init__(      self				:     str					,      __lowerCamelCase				:     List[str]=4_04_78					,      __lowerCamelCase				:     List[Any]=5_12					,      __lowerCamelCase				:     List[str]=7_68					,      __lowerCamelCase				:     List[str]=12					,      __lowerCamelCase				:     Optional[Any]=12					,      __lowerCamelCase				:     str="gelu"					,      __lowerCamelCase				:     Optional[int]=0.1					,      __lowerCamelCase				:     Any=0.1					,      __lowerCamelCase				:     Dict=0.1					,      __lowerCamelCase				:     Any=1e-5					,      __lowerCamelCase				:     Optional[int]=0.02					,      __lowerCamelCase				:     Optional[int]="cls_index"					,      __lowerCamelCase				:     List[Any]=True					,      __lowerCamelCase				:     Optional[int]=None					,      __lowerCamelCase				:     Optional[Any]=True					,      __lowerCamelCase				:     Tuple=0.1					,      **__lowerCamelCase				:     Union[str, Any]					,      )					->     List[str]:
							a    =			vocab_size
							a    =			n_positions
							a    =			n_embd
							a    =			n_layer
							a    =			n_head
							a    =			afn
							a    =			resid_pdrop
							a    =			embd_pdrop
							a    =			attn_pdrop
							a    =			layer_norm_epsilon
							a    =			initializer_range
							a    =			summary_type
							a    =			summary_use_proj
							a    =			summary_activation
							a    =			summary_first_dropout
							a    =			summary_proj_to_labels
							super().__init__(**__lowerCamelCase							)






