


'''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      snake_case    :





       """simple docstring"""




       @staticmethod
       def   snake_case		(    *UpperCamelCase			,  **UpperCamelCase     ):







        """simple docstring"""
        pass





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





  """simple docstring"""




  _lowerCamelCase		    =  MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING






  def   snake_case		(    self			,  UpperCamelCase			,  UpperCamelCase			,  UpperCamelCase     ):







   """simple docstring"""
   lowerCamelCase_      =  pipeline(
       "zero-shot-object-detection"			,  model="hf-internal-testing/tiny-random-owlvit-object-detection"     )

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






  def   snake_case		(    self			,  UpperCamelCase			,  UpperCamelCase     ):







   """simple docstring"""
   lowerCamelCase_      =  object_detector(examples[0]			,  threshold=0.0     )

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






  @require_tf
  @unittest.skip("Zero Shot Object Detection not implemented in TF"     )
  def   snake_case		(    self     ):







   """simple docstring"""
   pass






  @require_torch
  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  pipeline(
       "zero-shot-object-detection"			,  model="hf-internal-testing/tiny-random-owlvit-object-detection"     )

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

   self.assertEqual(
       nested_simplify(UpperCamelCase			,  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}},
       ]			,  )

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

   self.assertEqual(
       nested_simplify(UpperCamelCase			,  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     ):







   """simple docstring"""
   lowerCamelCase_      =  pipeline("zero-shot-object-detection"     )

   lowerCamelCase_      =  object_detector(
       "http://images.cocodataset.org/val2017/000000039769.jpg"			,  candidate_labels=["cat", "remote", "couch"]			,  )
   self.assertEqual(
       nested_simplify(UpperCamelCase			,  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}},
       ]			,  )

   lowerCamelCase_      =  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(UpperCamelCase			,  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     ):







   """simple docstring"""
   pass






  @require_torch
  @slow
  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  0.2
   lowerCamelCase_      =  pipeline("zero-shot-object-detection"     )

   lowerCamelCase_      =  object_detector(
       "http://images.cocodataset.org/val2017/000000039769.jpg"			,  candidate_labels=["cat", "remote", "couch"]			,  threshold=UpperCamelCase			,  )
   self.assertEqual(
       nested_simplify(UpperCamelCase			,  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     ):







   """simple docstring"""
   lowerCamelCase_      =  2
   lowerCamelCase_      =  pipeline("zero-shot-object-detection"     )

   lowerCamelCase_      =  object_detector(
       "http://images.cocodataset.org/val2017/000000039769.jpg"			,  candidate_labels=["cat", "remote", "couch"]			,  top_k=UpperCamelCase			,  )
   self.assertEqual(
       nested_simplify(UpperCamelCase			,  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 ....configuration_utils import PretrainedConfig
from ....utils import logging


__snake_case							:   List[Any]      =    logging.get_logger(__name__)

__snake_case							:   Any      =    {
    'speechbrain/m-ctc-t-large': 'https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json',
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}



class 			A__   (  __SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	'mctct'

	def __init__(     self:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		str=8065       ,			_SCREAMING_SNAKE_CASE:		str=1536       ,			_SCREAMING_SNAKE_CASE:		str=36       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=6144       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=4       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=384       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=920       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=1e-5       ,			_SCREAMING_SNAKE_CASE:		List[Any]=0.3       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]="relu"       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=0.02       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=0.3       ,			_SCREAMING_SNAKE_CASE:		Dict=0.3       ,			_SCREAMING_SNAKE_CASE:		List[Any]=1       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=0       ,			_SCREAMING_SNAKE_CASE:		List[str]=2       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=1       ,			_SCREAMING_SNAKE_CASE:		Tuple=0.3       ,			_SCREAMING_SNAKE_CASE:		Dict=1       ,			_SCREAMING_SNAKE_CASE:		int=(7,)       ,			_SCREAMING_SNAKE_CASE:		str=(3,)       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=80       ,			_SCREAMING_SNAKE_CASE:		Tuple=1       ,			_SCREAMING_SNAKE_CASE:		Dict=None       ,			_SCREAMING_SNAKE_CASE:		Tuple="sum"       ,			_SCREAMING_SNAKE_CASE:		List[str]=False       ,			**_SCREAMING_SNAKE_CASE:		Tuple       ,			)				->       Tuple:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE       ,			pad_token_id=_SCREAMING_SNAKE_CASE       ,			bos_token_id=_SCREAMING_SNAKE_CASE       ,			eos_token_id=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       vocab_size
				__lowerCAmelCase      :  str												=       hidden_size
				__lowerCAmelCase      :  str												=       num_hidden_layers
				__lowerCAmelCase      :  str												=       intermediate_size
				__lowerCAmelCase      :  List[Any]												=       num_attention_heads
				__lowerCAmelCase      :  Dict												=       attention_head_dim
				__lowerCAmelCase      :  Optional[int]												=       max_position_embeddings
				__lowerCAmelCase      :  str												=       layer_norm_eps
				__lowerCAmelCase      :  Tuple												=       layerdrop
				__lowerCAmelCase      :  str												=       hidden_act
				__lowerCAmelCase      :  List[Any]												=       initializer_range
				__lowerCAmelCase      :  int												=       hidden_dropout_prob
				__lowerCAmelCase      :  Optional[Any]												=       attention_probs_dropout_prob
				__lowerCAmelCase      :  str												=       pad_token_id
				__lowerCAmelCase      :  Optional[int]												=       bos_token_id
				__lowerCAmelCase      :  Union[str, Any]												=       eos_token_id
				__lowerCAmelCase      :  Any												=       conv_glu_dim
				__lowerCAmelCase      :  Optional[int]												=       conv_dropout
				__lowerCAmelCase      :  Union[str, Any]												=       num_conv_layers
				__lowerCAmelCase      :  Optional[int]												=       input_feat_per_channel
				__lowerCAmelCase      :  Union[str, Any]												=       input_channels
				__lowerCAmelCase      :  Optional[Any]												=       conv_channels
				__lowerCAmelCase      :  Dict												=       ctc_loss_reduction
				__lowerCAmelCase      :  int												=       ctc_zero_infinity

				# prevents config testing fail with exporting to json
				__lowerCAmelCase      :  List[str]												=       list(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Dict												=       list(_SCREAMING_SNAKE_CASE)

				if len(self.conv_kernel) != self.num_conv_layers:
							raise ValueError(
							    "Configuration for convolutional module is incorrect. "
							    "It is required that `len(config.conv_kernel)` == `config.num_conv_layers` "
							    F"""but is `len(config.conv_kernel) = {len(self.conv_kernel)}`, """
							    F"""`config.num_conv_layers = {self.num_conv_layers}`.""")