



"""simple docstring"""





from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase							:       int          =       logging.get_logger(__name__)

__lowerCAmelCase							:       int          =       {
    '''microsoft/swinv2-tiny-patch4-window8-256''': (
        '''https://huggingface.co/microsoft/swinv2-tiny-patch4-window8-256/resolve/main/config.json'''
    ),
}



class  _lowerCAmelCase     (					SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase      	=							'''swinv2'''

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





		def __init__(       self				,     _lowercase=2_2_4				,     _lowercase=4				,     _lowercase=3				,     _lowercase=9_6				,     _lowercase=[2, 2, 6, 2]				,     _lowercase=[3, 6, 1_2, 2_4]				,     _lowercase=7				,     _lowercase=4.0				,     _lowercase=True				,     _lowercase=0.0				,     _lowercase=0.0				,     _lowercase=0.1				,     _lowercase="gelu"				,     _lowercase=False				,     _lowercase=0.02				,     _lowercase=1E-5				,     _lowercase=3_2				,     **_lowercase				,     )			->    Any:







								'''simple docstring'''

								super().__init__(**_lowercase )

								snake_case_ :			Optional[int]            =      image_size
								snake_case_ :			List[str]            =      patch_size
								snake_case_ :			str            =      num_channels
								snake_case_ :			Union[str, Any]            =      embed_dim
								snake_case_ :			List[str]            =      depths
								snake_case_ :			Any            =      len(_lowercase )
								snake_case_ :			Union[str, Any]            =      num_heads
								snake_case_ :			Dict            =      window_size
								snake_case_ :			Optional[Any]            =      mlp_ratio
								snake_case_ :			Tuple            =      qkv_bias
								snake_case_ :			str            =      hidden_dropout_prob
								snake_case_ :			Dict            =      attention_probs_dropout_prob
								snake_case_ :			List[Any]            =      drop_path_rate
								snake_case_ :			Optional[int]            =      hidden_act
								snake_case_ :			str            =      use_absolute_embeddings
								snake_case_ :			Union[str, Any]            =      layer_norm_eps
								snake_case_ :			Any            =      initializer_range
								snake_case_ :			Union[str, Any]            =      encoder_stride
								# we set the hidden_size attribute in order to make Swinv2 work with VisionEncoderDecoderModel
								# this indicates the channel dimension after the last stage of the model
								snake_case_ :			Optional[Any]            =      int(embed_dim * 2 ** (len(_lowercase ) - 1) )
								snake_case_ :			List[str]            =      (0, 0, 0, 0)








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 ):
 __SCREAMING_SNAKE_CASE							=      MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



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



 def 							UpperCamelCase     (				self,__lowerCamelCase,__lowerCamelCase					):
        for example in examples:
               A__		   =		video_classifier(__lowerCamelCase					)

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



 @require_torch
 def 							UpperCamelCase     (				self					):
        A__		   =		'''hf-internal-testing/tiny-random-VideoMAEForVideoClassification'''
        A__		   =		VideoMAEFeatureExtractor(
            size={'''shortest_edge''': 10},crop_size={'''height''': 10, '''width''': 10}					)
        A__		   =		pipeline(
            '''video-classification''',model=__lowerCamelCase,feature_extractor=__lowerCamelCase,frame_sampling_rate=4					)

        A__		   =		hf_hub_download(repo_id='''nateraw/video-demo''',filename='''archery.mp4''',repo_type='''dataset'''					)
        A__		   =		video_classifier(__lowerCamelCase,top_k=2					)
        self.assertEqual(
            nested_simplify(__lowerCamelCase,decimals=4					),[{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],)

        A__		   =		video_classifier(
            [
                video_file_path,
                video_file_path,
            ],top_k=2,)
        self.assertEqual(
            nested_simplify(__lowerCamelCase,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 							UpperCamelCase     (				self					):
        pass





