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


        @staticmethod
        def    lowerCAmelCase_     (    *__lowerCAmelCase		:     Optional[int]      , **__lowerCAmelCase		:     Dict    ):
          pass


@is_pipeline_test
@require_vision
@require_torch
class 				a (						unittest.TestCase      ):
    _snake_case   :     Tuple   							=							MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING


    def    lowerCAmelCase_     (    self		:     Any      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     Optional[Any]    ):
      _UpperCAmelCase         =					pipeline(
          """zero-shot-object-detection"""      , model="""hf-internal-testing/tiny-random-owlvit-object-detection"""    )

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


    def    lowerCAmelCase_     (    self		:     Optional[Any]      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     List[Any]    ):
      _UpperCAmelCase         =					object_detector(examples[0]      , threshold=0.0    )

      _UpperCAmelCase         =					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    lowerCAmelCase_     (    self		:     int    ):
      pass


    @require_torch
    def    lowerCAmelCase_     (    self		:     Optional[int]    ):
      _UpperCAmelCase         =					pipeline(
          """zero-shot-object-detection"""      , model="""hf-internal-testing/tiny-random-owlvit-object-detection"""    )

      _UpperCAmelCase         =					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""": 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}},
          ]      , )

      _UpperCAmelCase         =					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""": 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    lowerCAmelCase_     (    self		:     Any    ):
      _UpperCAmelCase         =					pipeline("""zero-shot-object-detection"""    )

      _UpperCAmelCase         =					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""": 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}},
          ]      , )

      _UpperCAmelCase         =					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""": 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    lowerCAmelCase_     (    self		:     Any    ):
      pass


    @require_torch
    @slow
    def    lowerCAmelCase_     (    self		:     int    ):
      _UpperCAmelCase         =					0.2
      _UpperCAmelCase         =					pipeline("""zero-shot-object-detection"""    )

      _UpperCAmelCase         =					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""": 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    lowerCAmelCase_     (    self		:     Dict    ):
      _UpperCAmelCase         =					2
      _UpperCAmelCase         =					pipeline("""zero-shot-object-detection"""    )

      _UpperCAmelCase         =					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""": 324, """ymin""": 20, """xmax""": 640, """ymax""": 373}},
              {"""score""": 0.277, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 177, """ymax""": 115}},
          ]      , )

"""simple docstring"""


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


UpperCAmelCase__     						=  logging.get_logger(__name__)

UpperCAmelCase__     						=  {
    """google/efficientnet-b7""": """https://huggingface.co/google/efficientnet-b7/resolve/main/config.json""",
}


class 				a (						lowerCAmelCase_      ):
    _snake_case   :     Any   							=							'efficientnet'


    def __init__(    self		:     Any      , __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[Any]      , ):
      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 				a (						lowerCAmelCase_      ):
    _snake_case   :     Dict   							=							version.parse('1.11'      )


    @property
    def    lowerCAmelCase_     (    self		:     Any    ):
      return OrderedDict(
          [
              ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
          ]    )


    @property
    def    lowerCAmelCase_     (    self		:     int    ):
      return 1e-5
