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






      _snake_case    		=       MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



      def 	_SCREAMING_SNAKE_CASE    (					self     :				str    ,  _UpperCamelCase     :				List[str]    ,  _UpperCamelCase     :				str    ,  _UpperCamelCase     :				List[str])				->str:


          """simple docstring"""


          _lowerCamelCase     :		Any 						=						hf_hub_download(
              repo_id="""nateraw/video-demo"""    ,  filename="""archery.mp4"""    ,  repo_type="""dataset""")
          _lowerCamelCase     :		List[Any] 						=						VideoClassificationPipeline(model=_UpperCamelCase    ,  image_processor=_UpperCamelCase    ,  top_k=2)
          _lowerCamelCase     :		Tuple 						=						[
              example_video_filepath,
              """https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4""",
          ]
          return video_classifier, examples



      def 	_SCREAMING_SNAKE_CASE    (					self     :				Optional[int]    ,  _UpperCamelCase     :				List[Any]    ,  _UpperCamelCase     :				List[Any])				->Any:


          """simple docstring"""


          for example in examples:
              _lowerCamelCase     :		Any 						=						video_classifier(_UpperCamelCase)

              self.assertEqual(
                  _UpperCamelCase    ,  [
                      {"""score""": ANY(_UpperCamelCase), """label""": ANY(_UpperCamelCase)},
                      {"""score""": ANY(_UpperCamelCase), """label""": ANY(_UpperCamelCase)},
                  ]    ,  )



      @require_torch
      def 	_SCREAMING_SNAKE_CASE    (					self     :				Any)				->str:


          """simple docstring"""


          _lowerCamelCase     :		Tuple 						=						"""hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
          _lowerCamelCase     :		Any 						=						VideoMAEFeatureExtractor(
              size={"""shortest_edge""": 10}    ,  crop_size={"""height""": 10, """width""": 10})
          _lowerCamelCase     :		str 						=						pipeline(
              """video-classification"""    ,  model=_UpperCamelCase    ,  feature_extractor=_UpperCamelCase    ,  frame_sampling_rate=4)

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

          _lowerCamelCase     :		List[Any] 						=						video_classifier(
              [
                  video_file_path,
                  video_file_path,
              ]    ,  top_k=2    ,  )
          self.assertEqual(
              nested_simplify(_UpperCamelCase    ,  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 	_SCREAMING_SNAKE_CASE    (					self     :				Any)				->List[Any]:


          """simple docstring"""


          pass





from collections import OrderedDict
from typing import Mapping

from packaging import version

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


lowerCAmelCase			:							Any     =logging.get_logger(__name__)

lowerCAmelCase			:							List[Any]     ={
    "microsoft/swin-tiny-patch4-window7-224": (
        "https://huggingface.co/microsoft/swin-tiny-patch4-window7-224/resolve/main/config.json"
    ),
    # See all Swin models at https://huggingface.co/models?filter=swin
}




class 	__snake_case	( __lowerCAmelCase ,  __lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       'swin'

      _snake_case    		=       {
          'num_attention_heads': 'num_heads',
          'num_hidden_layers': 'num_layers',
      }



      def __init__(					self     :				Optional[int]    ,  _UpperCamelCase     :				List[str]=224    ,  _UpperCamelCase     :				List[str]=4    ,  _UpperCamelCase     :				List[Any]=3    ,  _UpperCamelCase     :				Dict=96    ,  _UpperCamelCase     :				Any=[2, 2, 6, 2]    ,  _UpperCamelCase     :				Any=[3, 6, 12, 24]    ,  _UpperCamelCase     :				Tuple=7    ,  _UpperCamelCase     :				Tuple=4.0    ,  _UpperCamelCase     :				Dict=True    ,  _UpperCamelCase     :				Tuple=0.0    ,  _UpperCamelCase     :				Any=0.0    ,  _UpperCamelCase     :				Optional[int]=0.1    ,  _UpperCamelCase     :				Any="gelu"    ,  _UpperCamelCase     :				str=False    ,  _UpperCamelCase     :				str=0.0_2    ,  _UpperCamelCase     :				Dict=1E-5    ,  _UpperCamelCase     :				List[str]=32    ,  _UpperCamelCase     :				Optional[Any]=None    ,  _UpperCamelCase     :				List[Any]=None    ,  **_UpperCamelCase     :				List[Any]    ,  )				->Tuple:


          """simple docstring"""


          super().__init__(**_UpperCamelCase)

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





class 	__snake_case	( __lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       version.parse('1.11'		)



      @property
      def 	_SCREAMING_SNAKE_CASE    (					self     :				Tuple)				->Mapping[str, Mapping[int, str]]:


          """simple docstring"""


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




      @property
      def 	_SCREAMING_SNAKE_CASE    (					self     :				Union[str, Any])				->float:


          """simple docstring"""


          return 1E-4




