





"""simple docstring"""



import unittest

from huggingface_hub import hf_hub_download

from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VideoMAEFeatureExtractor
from transformers.pipelines import VideoClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_decord,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
)

from .test_pipelines_common import ANY






@is_pipeline_test
@require_torch_or_tf
@require_vision
@require_decord
class 		__snake_case (		unittest.TestCase					):





 """simple docstring"""


 _lowerCamelCase				=					MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						str									=					hf_hub_download(
         repo_id='''nateraw/video-demo''' ,						filename='''archery.mp4''' ,						repo_type='''dataset'''  )
     __A   :						Optional[int]									=					VideoClassificationPipeline(model=__lowerCamelCase ,						image_processor=__lowerCamelCase ,						top_k=2  )
     __A   :						int									=					[
         example_video_filepath,
         '''https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4''',
     ]
     return video_classifier, examples

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase  ):



     '''simple docstring'''




     for example in examples:
         __A   :						List[Any]									=					video_classifier(__lowerCamelCase  )

         self.assertEqual(
             __lowerCamelCase ,						[
                 {'''score''': ANY(__lowerCamelCase  ), '''label''': ANY(__lowerCamelCase  )},
                 {'''score''': ANY(__lowerCamelCase  ), '''label''': ANY(__lowerCamelCase  )},
             ] ,						)

 @require_torch
 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Union[str, Any]									=					'''hf-internal-testing/tiny-random-VideoMAEForVideoClassification'''
     __A   :						Optional[Any]									=					VideoMAEFeatureExtractor(
         size={'''shortest_edge''': 10} ,						crop_size={'''height''': 10, '''width''': 10}  )
     __A   :						Optional[Any]									=					pipeline(
         '''video-classification''' ,						model=__lowerCamelCase ,						feature_extractor=__lowerCamelCase ,						frame_sampling_rate=4  )

     __A   :						Dict									=					hf_hub_download(repo_id='''nateraw/video-demo''' ,						filename='''archery.mp4''' ,						repo_type='''dataset'''  )
     __A   :						Tuple									=					video_classifier(__lowerCamelCase ,						top_k=2  )
     self.assertEqual(
         nested_simplify(__lowerCamelCase ,						decimals=4  ) ,						[{'''score''': 0.5_1_9_9, '''label''': '''LABEL_0'''}, {'''score''': 0.4_8_0_1, '''label''': '''LABEL_1'''}] ,						)

     __A   :						Optional[int]									=					video_classifier(
         [
             video_file_path,
             video_file_path,
         ] ,						top_k=2 ,						)
     self.assertEqual(
         nested_simplify(__lowerCamelCase ,						decimals=4  ) ,						[
             [{'''score''': 0.5_1_9_9, '''label''': '''LABEL_0'''}, {'''score''': 0.4_8_0_1, '''label''': '''LABEL_1'''}],
             [{'''score''': 0.5_1_9_9, '''label''': '''LABEL_0'''}, {'''score''': 0.4_8_0_1, '''label''': '''LABEL_1'''}],
         ] ,						)







 @require_tf
 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     pass











"""simple docstring"""



from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


a_			=      logging.get_logger(__name__)

a_			=      {
    """shi-labs/dinat-mini-in1k-224""": """https://huggingface.co/shi-labs/dinat-mini-in1k-224/resolve/main/config.json""",
    # See all Dinat models at https://huggingface.co/models?filter=dinat
}






class 		__snake_case (		SCREAMING_SNAKE_CASE__							,							SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 _lowerCamelCase				=					"""dinat"""

 _lowerCamelCase				=					{
     """num_attention_heads""": """num_heads""",
     """num_hidden_layers""": """num_layers""",
 }

 def __init__(   self ,						__lowerCamelCase=4 ,						__lowerCamelCase=3 ,						__lowerCamelCase=64 ,						__lowerCamelCase=[3, 4, 6, 5] ,						__lowerCamelCase=[2, 4, 8, 16] ,						__lowerCamelCase=7 ,						__lowerCamelCase=[[1, 8, 1], [1, 4, 1, 4], [1, 2, 1, 2, 1, 2], [1, 1, 1, 1, 1]] ,						__lowerCamelCase=3.0 ,						__lowerCamelCase=True ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=0.1 ,						__lowerCamelCase="gelu" ,						__lowerCamelCase=0.0_2 ,						__lowerCamelCase=1e-5 ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=None ,						__lowerCamelCase=None ,						**__lowerCamelCase ,						):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase  )

     __A   :						Dict									=					patch_size
     __A   :						Union[str, Any]									=					num_channels
     __A   :						str									=					embed_dim
     __A   :						Optional[Any]									=					depths
     __A   :						int									=					len(__lowerCamelCase  )
     __A   :						Union[str, Any]									=					num_heads
     __A   :						Tuple									=					kernel_size
     __A   :						Optional[int]									=					dilations
     __A   :						Tuple									=					mlp_ratio
     __A   :						Optional[int]									=					qkv_bias
     __A   :						int									=					hidden_dropout_prob
     __A   :						Dict									=					attention_probs_dropout_prob
     __A   :						int									=					drop_path_rate
     __A   :						Dict									=					hidden_act
     __A   :						Any									=					layer_norm_eps
     __A   :						Tuple									=					initializer_range
     # we set the hidden_size attribute in order to make Dinat work with VisionEncoderDecoderModel
     # this indicates the channel dimension after the last stage of the model
     __A   :						str									=					int(embed_dim * 2 ** (len(__lowerCamelCase  ) - 1)  )
     __A   :						List[Any]									=					layer_scale_init_value
     __A   :						Any									=					['''stem'''] + [F"""stage{idx}""" for idx in range(1 ,						len(__lowerCamelCase  ) + 1  )]
     __A			,	__A   :						Union[str, Any]									=					get_aligned_output_features_output_indices(
         out_features=__lowerCamelCase ,						out_indices=__lowerCamelCase ,						stage_names=self.stage_names  )




