



'''simple docstring'''






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


A_							: Dict						 =	logging.get_logger(__name__)

A_							: List[str]						 =	{
    """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 							lowercase       (  _lowerCamelCase					,					_lowerCamelCase				):


 """simple docstring"""


 UpperCAmelCase							=  "swin"

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







 def __init__(							self  ,a_=224  ,a_=4  ,a_=3  ,a_=96  ,a_=[2, 2, 6, 2]  ,a_=[3, 6, 12, 24]  ,a_=7  ,a_=4.0  ,a_=True  ,a_=0.0  ,a_=0.0  ,a_=0.1  ,a_="gelu"  ,a_=False  ,a_=0.02  ,a_=1E-5  ,a_=32  ,a_=None  ,a_=None  ,**a_  ,)		->   Dict:
        super().__init__(**snake_case__							)

        _UpperCAmelCase  :						Any			     = image_size
        _UpperCAmelCase  :						Union[str, Any]			     = patch_size
        _UpperCAmelCase  :						List[Any]			     = num_channels
        _UpperCAmelCase  :						Tuple			     = embed_dim
        _UpperCAmelCase  :						Any			     = depths
        _UpperCAmelCase  :						List[Any]			     = len(snake_case__							)
        _UpperCAmelCase  :						List[str]			     = num_heads
        _UpperCAmelCase  :						Union[str, Any]			     = window_size
        _UpperCAmelCase  :						Optional[Any]			     = mlp_ratio
        _UpperCAmelCase  :						List[str]			     = qkv_bias
        _UpperCAmelCase  :						int			     = hidden_dropout_prob
        _UpperCAmelCase  :						Union[str, Any]			     = attention_probs_dropout_prob
        _UpperCAmelCase  :						Any			     = drop_path_rate
        _UpperCAmelCase  :						Optional[int]			     = hidden_act
        _UpperCAmelCase  :						Optional[int]			     = use_absolute_embeddings
        _UpperCAmelCase  :						int			     = layer_norm_eps
        _UpperCAmelCase  :						int			     = initializer_range
        _UpperCAmelCase  :						Optional[Any]			     = 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
        _UpperCAmelCase  :						int			     = int(embed_dim * 2 ** (len(snake_case__							) - 1)							)
        _UpperCAmelCase  :						Tuple			     = ["stem"] + [f'''stage{idx}''' for idx in range(1  ,len(snake_case__							) + 1							)]
        _UpperCAmelCase  :						List[Any]			     = get_aligned_output_features_output_indices(
            out_features=snake_case__  ,out_indices=snake_case__  ,stage_names=self.stage_names							)







class 							lowercase       (  _lowerCamelCase				):


 """simple docstring"""


 UpperCAmelCase							=  version.parse("""1.11"""				)







 @property
 def _snake_case (							self							)		->   Optional[int]:
        return OrderedDict(
            [
                ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
            ]							)







 @property
 def _snake_case (							self							)		->   Optional[Any]:
        return 1E-4







"""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       SCREAMING_SNAKE_CASE__				(		unittest.TestCase				):
       """simple docstring"""


       a  :				int   =MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





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

       def        lowercase__							(						self		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         for example in examples:
           lowerCAmelCase     :     str								=							video_classifier(snake_case__						)

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

       @require_torch
       def        lowercase__							(						self						):






         """simple docstring"""





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

         lowerCAmelCase     :     Optional[int]								=							hf_hub_download(repo_id="nateraw/video-demo"		,     filename="archery.mp4"		,     repo_type="dataset"						)
         lowerCAmelCase     :     Union[str, Any]								=							video_classifier(snake_case__		,     top_k=2						)
         self.assertEqual(
             nested_simplify(snake_case__		,     decimals=4						)		,     [{"score": 0.5199, "label": "LABEL_0"}, {"score": 0.4801, "label": "LABEL_1"}]		,     )

         lowerCAmelCase     :     Tuple								=							video_classifier(
             [
                 video_file_path,
                 video_file_path,
             ]		,     top_k=2		,     )
         self.assertEqual(
             nested_simplify(snake_case__		,     decimals=4						)		,     [
                 [{"score": 0.5199, "label": "LABEL_0"}, {"score": 0.4801, "label": "LABEL_1"}],
                 [{"score": 0.5199, "label": "LABEL_0"}, {"score": 0.4801, "label": "LABEL_1"}],
             ]		,     )







       @require_tf
       def        lowercase__							(						self						):






         """simple docstring"""





         pass





