





import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..bit import BitConfig


_lowerCamelCase   				=			logging.get_logger(__name__)

_lowerCamelCase   				=			{
    'Intel/dpt-large': 'https://huggingface.co/Intel/dpt-large/resolve/main/config.json',
    # See all DPT models at https://huggingface.co/models?filter=dpt
}




class   UpperCamelCase_       (     UpperCamelCase__    ):
							lowerCamelCase_           =					"dpt"


							def __init__(							self    :Union[str, Any]							,				__A    :int=768							,				__A    :Optional[int]=12							,				__A    :Optional[Any]=12							,				__A    :Dict=3072							,				__A    :Optional[Any]="gelu"							,				__A    :Union[str, Any]=0.0							,				__A    :Optional[Any]=0.0							,				__A    :int=0.0_2							,				__A    :Optional[Any]=1E-12							,				__A    :Union[str, Any]=384							,				__A    :int=16							,				__A    :Tuple=3							,				__A    :Tuple=False							,				__A    :int=True							,				__A    :Optional[Any]=[2, 5, 8, 11]							,				__A    :Any="project"							,				__A    :Any=[4, 2, 1, 0.5]							,				__A    :str=[96, 192, 384, 768]							,				__A    :int=256							,				__A    :Union[str, Any]=-1							,				__A    :List[Any]=False							,				__A    :int=True							,				__A    :List[Any]=0.4							,				__A    :Any=255							,				__A    :Any=0.1							,				__A    :Tuple=[1, 1024, 24, 24]							,				__A    :int=[0, 1]							,				__A    :Union[str, Any]=None							,				**__A    :Dict							,				)   ->   Optional[Any]:



									"""simple docstring"""



									super().__init__(**__A		)

									SCREAMING_SNAKE_CASE__			=      hidden_size
									SCREAMING_SNAKE_CASE__			=      is_hybrid

									if self.is_hybrid:
											if backbone_config is None:
													logger.info("""Initializing the config with a `BiT` backbone."""		)
													SCREAMING_SNAKE_CASE__			=      {
													    """global_padding""": """same""",
													    """layer_type""": """bottleneck""",
													    """depths""": [3, 4, 9],
													    """out_features""": ["""stage1""", """stage2""", """stage3"""],
													    """embedding_dynamic_padding""": True,
													}
													SCREAMING_SNAKE_CASE__			=      BitConfig(**__A		)
											elif isinstance(__A							,				__A		):
													logger.info("""Initializing the config with a `BiT` backbone."""		)
													SCREAMING_SNAKE_CASE__			=      BitConfig(**__A		)
											elif isinstance(__A							,				__A		):
													SCREAMING_SNAKE_CASE__			=      backbone_config
											else:
													raise ValueError(
													    f'''backbone_config must be a dictionary or a `PretrainedConfig`, got {backbone_config.__class__}.'''		)

											SCREAMING_SNAKE_CASE__			=      backbone_featmap_shape
											SCREAMING_SNAKE_CASE__			=      neck_ignore_stages

											if readout_type != "project":
													raise ValueError("""Readout type must be 'project' when using `DPT-hybrid` mode."""		)
									else:
											SCREAMING_SNAKE_CASE__			=      None
											SCREAMING_SNAKE_CASE__			=      None
											SCREAMING_SNAKE_CASE__			=      []

									SCREAMING_SNAKE_CASE__			=      num_hidden_layers
									SCREAMING_SNAKE_CASE__			=      num_attention_heads
									SCREAMING_SNAKE_CASE__			=      intermediate_size
									SCREAMING_SNAKE_CASE__			=      hidden_act
									SCREAMING_SNAKE_CASE__			=      hidden_dropout_prob
									SCREAMING_SNAKE_CASE__			=      attention_probs_dropout_prob
									SCREAMING_SNAKE_CASE__			=      initializer_range
									SCREAMING_SNAKE_CASE__			=      layer_norm_eps
									SCREAMING_SNAKE_CASE__			=      image_size
									SCREAMING_SNAKE_CASE__			=      patch_size
									SCREAMING_SNAKE_CASE__			=      num_channels
									SCREAMING_SNAKE_CASE__			=      qkv_bias
									SCREAMING_SNAKE_CASE__			=      backbone_out_indices
									if readout_type not in ["ignore", "add", "project"]:
											raise ValueError("""Readout_type must be one of ['ignore', 'add', 'project']"""		)
									SCREAMING_SNAKE_CASE__			=      readout_type
									SCREAMING_SNAKE_CASE__			=      reassemble_factors
									SCREAMING_SNAKE_CASE__			=      neck_hidden_sizes
									SCREAMING_SNAKE_CASE__			=      fusion_hidden_size
									SCREAMING_SNAKE_CASE__			=      head_in_index
									SCREAMING_SNAKE_CASE__			=      use_batch_norm_in_fusion_residual
									# auxiliary head attributes (semantic segmentation)
									SCREAMING_SNAKE_CASE__			=      use_auxiliary_head
									SCREAMING_SNAKE_CASE__			=      auxiliary_loss_weight
									SCREAMING_SNAKE_CASE__			=      semantic_loss_ignore_index
									SCREAMING_SNAKE_CASE__			=      semantic_classifier_dropout


							def      _snake_case  (							self    :Any		)   ->   Tuple:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__			=      copy.deepcopy(self.__dict__		)

									if output["backbone_config"] is not None:
											SCREAMING_SNAKE_CASE__			=      self.backbone_config.to_dict()

									SCREAMING_SNAKE_CASE__			=      self.__class__.model_type
									return output






import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow




@is_pipeline_test
@require_torch
class   UpperCamelCase_       (     unittest.TestCase    ):


							@require_torch
							def      _snake_case  (							self    :Dict		)   ->   Optional[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__			=      pipeline(
									    task="""zero-shot-audio-classification"""							,				model="""hf-internal-testing/tiny-clap-htsat-unfused"""		)
									SCREAMING_SNAKE_CASE__			=      load_dataset("""ashraq/esc50"""		)
									SCREAMING_SNAKE_CASE__			=      dataset["""train"""]["""audio"""][-1]["""array"""]
									SCREAMING_SNAKE_CASE__			=      audio_classifier(__A							,				candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]		)
									self.assertEqual(
									    nested_simplify(__A		)							,				[{"""score""": 0.5_0_1, """label""": """Sound of a dog"""}, {"""score""": 0.4_9_9, """label""": """Sound of vaccum cleaner"""}]							,				)


							@unittest.skip("""No models are available in TF"""		)
							def      _snake_case  (							self    :Dict		)   ->   List[str]:



									"""simple docstring"""



									pass


							@slow
							@require_torch
							def      _snake_case  (							self    :Any		)   ->   int:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__			=      pipeline(
									    task="""zero-shot-audio-classification"""							,				model="""laion/clap-htsat-unfused"""							,				)
									# This is an audio of a dog
									SCREAMING_SNAKE_CASE__			=      load_dataset("""ashraq/esc50"""		)
									SCREAMING_SNAKE_CASE__			=      dataset["""train"""]["""audio"""][-1]["""array"""]
									SCREAMING_SNAKE_CASE__			=      audio_classifier(__A							,				candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]		)

									self.assertEqual(
									    nested_simplify(__A		)							,				[
									        {"""score""": 0.9_9_9, """label""": """Sound of a dog"""},
									        {"""score""": 0.0_0_1, """label""": """Sound of vaccum cleaner"""},
									    ]							,				)

									SCREAMING_SNAKE_CASE__			=      audio_classifier([audio] * 5							,				candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]		)
									self.assertEqual(
									    nested_simplify(__A		)							,				[
									        [
									            {"""score""": 0.9_9_9, """label""": """Sound of a dog"""},
									            {"""score""": 0.0_0_1, """label""": """Sound of vaccum cleaner"""},
									        ],
									    ]
									    * 5							,				)
									SCREAMING_SNAKE_CASE__			=      audio_classifier(
									    [audio] * 5							,				candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]							,				batch_size=5		)
									self.assertEqual(
									    nested_simplify(__A		)							,				[
									        [
									            {"""score""": 0.9_9_9, """label""": """Sound of a dog"""},
									            {"""score""": 0.0_0_1, """label""": """Sound of vaccum cleaner"""},
									        ],
									    ]
									    * 5							,				)


							@unittest.skip("""No models are available in TF"""		)
							def      _snake_case  (							self    :str		)   ->   Optional[int]:



									"""simple docstring"""



									pass