




'''simple docstring'''







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 					_a :





           '''simple docstring'''



           @staticmethod
           def 			snake_case_      (				*__a							,**__a							)      ->				str:
                pass







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





     '''simple docstring'''



     lowerCAmelCase_  :     int          =					MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING







     def 			snake_case_      (				self							,__a							,__a							,__a							)      ->				Dict:
          snake_case			:      List[Any]        =			pipeline(
              """zero-shot-object-detection"""							,model="""hf-internal-testing/tiny-random-owlvit-object-detection"""							)

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







     def 			snake_case_      (				self							,__a							,__a							)      ->				Optional[Any]:
          snake_case			:      Tuple        =			object_detector(examples[0]							,threshold=0.0							)

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







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







     @require_torch
     def 			snake_case_      (				self							)      ->				Any:
          snake_case			:      Dict        =			pipeline(
              """zero-shot-object-detection"""							,model="""hf-internal-testing/tiny-random-owlvit-object-detection"""							)

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

          self.assertEqual(
              nested_simplify(__a							,decimals=4							)							,[
                  {"""score""": 0.7_235, """label""": """cat""", """box""": {"""xmin""": 204, """ymin""": 167, """xmax""": 232, """ymax""": 190}},
                  {"""score""": 0.7_218, """label""": """remote""", """box""": {"""xmin""": 204, """ymin""": 167, """xmax""": 232, """ymax""": 190}},
                  {"""score""": 0.7_184, """label""": """couch""", """box""": {"""xmin""": 204, """ymin""": 167, """xmax""": 232, """ymax""": 190}},
                  {"""score""": 0.6_748, """label""": """remote""", """box""": {"""xmin""": 571, """ymin""": 83, """xmax""": 598, """ymax""": 103}},
                  {"""score""": 0.6_656, """label""": """cat""", """box""": {"""xmin""": 571, """ymin""": 83, """xmax""": 598, """ymax""": 103}},
                  {"""score""": 0.6_614, """label""": """couch""", """box""": {"""xmin""": 571, """ymin""": 83, """xmax""": 598, """ymax""": 103}},
                  {"""score""": 0.6_456, """label""": """remote""", """box""": {"""xmin""": 494, """ymin""": 105, """xmax""": 521, """ymax""": 127}},
                  {"""score""": 0.642, """label""": """remote""", """box""": {"""xmin""": 67, """ymin""": 274, """xmax""": 93, """ymax""": 297}},
                  {"""score""": 0.6_419, """label""": """cat""", """box""": {"""xmin""": 494, """ymin""": 105, """xmax""": 521, """ymax""": 127}},
              ]							,)

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

          self.assertEqual(
              nested_simplify(__a							,decimals=4							)							,[
                  [
                      {"""score""": 0.7_235, """label""": """cat""", """box""": {"""xmin""": 204, """ymin""": 167, """xmax""": 232, """ymax""": 190}},
                      {"""score""": 0.7_218, """label""": """remote""", """box""": {"""xmin""": 204, """ymin""": 167, """xmax""": 232, """ymax""": 190}},
                      {"""score""": 0.7_184, """label""": """couch""", """box""": {"""xmin""": 204, """ymin""": 167, """xmax""": 232, """ymax""": 190}},
                      {"""score""": 0.6_748, """label""": """remote""", """box""": {"""xmin""": 571, """ymin""": 83, """xmax""": 598, """ymax""": 103}},
                      {"""score""": 0.6_656, """label""": """cat""", """box""": {"""xmin""": 571, """ymin""": 83, """xmax""": 598, """ymax""": 103}},
                      {"""score""": 0.6_614, """label""": """couch""", """box""": {"""xmin""": 571, """ymin""": 83, """xmax""": 598, """ymax""": 103}},
                      {"""score""": 0.6_456, """label""": """remote""", """box""": {"""xmin""": 494, """ymin""": 105, """xmax""": 521, """ymax""": 127}},
                      {"""score""": 0.642, """label""": """remote""", """box""": {"""xmin""": 67, """ymin""": 274, """xmax""": 93, """ymax""": 297}},
                      {"""score""": 0.6_419, """label""": """cat""", """box""": {"""xmin""": 494, """ymin""": 105, """xmax""": 521, """ymax""": 127}},
                  ]
              ]							,)







     @require_torch
     @slow
     def 			snake_case_      (				self							)      ->				Optional[Any]:
          snake_case			:      Tuple        =			pipeline("""zero-shot-object-detection"""							)

          snake_case			:      Tuple        =			object_detector(
              """http://images.cocodataset.org/val2017/000000039769.jpg"""							,candidate_labels=["""cat""", """remote""", """couch"""]							,)
          self.assertEqual(
              nested_simplify(__a							,decimals=4							)							,[
                  {"""score""": 0.2_868, """label""": """cat""", """box""": {"""xmin""": 324, """ymin""": 20, """xmax""": 640, """ymax""": 373}},
                  {"""score""": 0.277, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 177, """ymax""": 115}},
                  {"""score""": 0.2_537, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 55, """xmax""": 315, """ymax""": 472}},
                  {"""score""": 0.1_474, """label""": """remote""", """box""": {"""xmin""": 335, """ymin""": 74, """xmax""": 371, """ymax""": 187}},
                  {"""score""": 0.1_208, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 642, """ymax""": 476}},
              ]							,)

          snake_case			:      List[Any]        =			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(__a							,decimals=4							)							,[
                  [
                      {"""score""": 0.2_868, """label""": """cat""", """box""": {"""xmin""": 324, """ymin""": 20, """xmax""": 640, """ymax""": 373}},
                      {"""score""": 0.277, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 177, """ymax""": 115}},
                      {"""score""": 0.2_537, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 55, """xmax""": 315, """ymax""": 472}},
                      {"""score""": 0.1_474, """label""": """remote""", """box""": {"""xmin""": 335, """ymin""": 74, """xmax""": 371, """ymax""": 187}},
                      {"""score""": 0.1_208, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 642, """ymax""": 476}},
                  ],
                  [
                      {"""score""": 0.2_868, """label""": """cat""", """box""": {"""xmin""": 324, """ymin""": 20, """xmax""": 640, """ymax""": 373}},
                      {"""score""": 0.277, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 177, """ymax""": 115}},
                      {"""score""": 0.2_537, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 55, """xmax""": 315, """ymax""": 472}},
                      {"""score""": 0.1_474, """label""": """remote""", """box""": {"""xmin""": 335, """ymin""": 74, """xmax""": 371, """ymax""": 187}},
                      {"""score""": 0.1_208, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 642, """ymax""": 476}},
                  ],
              ]							,)







     @require_tf
     @unittest.skip("""Zero Shot Object Detection not implemented in TF"""							)
     def 			snake_case_      (				self							)      ->				Tuple:
          pass







     @require_torch
     @slow
     def 			snake_case_      (				self							)      ->				Tuple:
          snake_case			:      Tuple        =			0.2
          snake_case			:      Union[str, Any]        =			pipeline("""zero-shot-object-detection"""							)

          snake_case			:      str        =			object_detector(
              """http://images.cocodataset.org/val2017/000000039769.jpg"""							,candidate_labels=["""cat""", """remote""", """couch"""]							,threshold=__a							,)
          self.assertEqual(
              nested_simplify(__a							,decimals=4							)							,[
                  {"""score""": 0.2_868, """label""": """cat""", """box""": {"""xmin""": 324, """ymin""": 20, """xmax""": 640, """ymax""": 373}},
                  {"""score""": 0.277, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 177, """ymax""": 115}},
                  {"""score""": 0.2_537, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 55, """xmax""": 315, """ymax""": 472}},
              ]							,)







     @require_torch
     @slow
     def 			snake_case_      (				self							)      ->				Union[str, Any]:
          snake_case			:      List[str]        =			2
          snake_case			:      Tuple        =			pipeline("""zero-shot-object-detection"""							)

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











from collections import OrderedDict
from typing import List, Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__a:     Dict   					=					logging.get_logger(__name__)

__a:     Optional[int]   					=					{
    '''google/efficientnet-b7''': '''https://huggingface.co/google/efficientnet-b7/resolve/main/config.json''',
}
class 		SCREAMING_SNAKE_CASE__	(  UpperCAmelCase     ):

  '''simple docstring'''







  _lowerCamelCase    =  '''efficientnet'''


  def __init__(      self		:			Dict       ,				lowerCamelCase		:			int = 3       ,				lowerCamelCase		:			int = 600       ,				lowerCamelCase		:			float = 2.0       ,				lowerCamelCase		:			float = 3.1       ,				lowerCamelCase		:			int = 8       ,				lowerCamelCase		:			List[int] = [3, 3, 5, 3, 5, 5, 3]       ,				lowerCamelCase		:			List[int] = [32, 16, 24, 40, 80, 112, 192]       ,				lowerCamelCase		:			List[int] = [16, 24, 40, 80, 112, 192, 320]       ,				lowerCamelCase		:			List[int] = []       ,				lowerCamelCase		:			List[int] = [1, 2, 2, 2, 1, 2, 1]       ,				lowerCamelCase		:			List[int] = [1, 2, 2, 3, 3, 4, 1]       ,				lowerCamelCase		:			List[int] = [1, 6, 6, 6, 6, 6, 6]       ,				lowerCamelCase		:			float = 0.25       ,				lowerCamelCase		:			str = "swish"       ,				lowerCamelCase		:			int = 2560       ,				lowerCamelCase		:			str = "mean"       ,				lowerCamelCase		:			float = 0.02       ,				lowerCamelCase		:			float = 0.001       ,				lowerCamelCase		:			float = 0.99       ,				lowerCamelCase		:			float = 0.5       ,				lowerCamelCase		:			float = 0.2       ,				**lowerCamelCase		:			List[str]       ,				)						->	Union[str, Any]:


         """simple docstring"""
         super().__init__(**lowerCamelCase							)

         _UpperCAmelCase							=    num_channels
         _UpperCAmelCase							=    image_size
         _UpperCAmelCase							=    width_coefficient
         _UpperCAmelCase							=    depth_coefficient
         _UpperCAmelCase							=    depth_divisor
         _UpperCAmelCase							=    kernel_sizes
         _UpperCAmelCase							=    in_channels
         _UpperCAmelCase							=    out_channels
         _UpperCAmelCase							=    depthwise_padding
         _UpperCAmelCase							=    strides
         _UpperCAmelCase							=    num_block_repeats
         _UpperCAmelCase							=    expand_ratios
         _UpperCAmelCase							=    squeeze_expansion_ratio
         _UpperCAmelCase							=    hidden_act
         _UpperCAmelCase							=    hidden_dim
         _UpperCAmelCase							=    pooling_type
         _UpperCAmelCase							=    initializer_range
         _UpperCAmelCase							=    batch_norm_eps
         _UpperCAmelCase							=    batch_norm_momentum
         _UpperCAmelCase							=    dropout_rate
         _UpperCAmelCase							=    drop_connect_rate
         _UpperCAmelCase							=    sum(lowerCamelCase							) * 4



class 		SCREAMING_SNAKE_CASE__	(  UpperCAmelCase     ):

  '''simple docstring'''







  _lowerCamelCase    =  version.parse('''1.11'''     )


  @property
  def  lowerCamelCase       (      self		:			Optional[Any]							)						->	Mapping[str, Mapping[int, str]]:


         """simple docstring"""
         return OrderedDict(
             [
                 ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
             ]							)





  @property
  def  lowerCamelCase       (      self		:			Dict							)						->	float:


         """simple docstring"""
         return 1E-5