




import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)





class 			__lowerCamelCase	(   unittest.TestCase   ):




    """simple docstring"""

    def        a				(	self					:					str       )				->	List[str]:
         lowerCAmelCase__          =			["a", "b", "c"]

         # Defaults to last layer if both are None
         lowerCAmelCase__     ,		lowerCAmelCase__          =			get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )
         self.assertEqual(SCREAMING_SNAKE_CASE__       ,     ["c"]       )
         self.assertEqual(SCREAMING_SNAKE_CASE__       ,     [2]       )

         # Out indices set to match out features
         lowerCAmelCase__     ,		lowerCAmelCase__          =			get_aligned_output_features_output_indices(["a", "c"]       ,     SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )
         self.assertEqual(SCREAMING_SNAKE_CASE__       ,     ["a", "c"]       )
         self.assertEqual(SCREAMING_SNAKE_CASE__       ,     [0, 2]       )

         # Out features set to match out indices
         lowerCAmelCase__     ,		lowerCAmelCase__          =			get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__       ,     [0, 2]       ,     SCREAMING_SNAKE_CASE__       )
         self.assertEqual(SCREAMING_SNAKE_CASE__       ,     ["a", "c"]       )
         self.assertEqual(SCREAMING_SNAKE_CASE__       ,     [0, 2]       )

         # Out features selected from negative indices
         lowerCAmelCase__     ,		lowerCAmelCase__          =			get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__       ,     [-3, -1]       ,     SCREAMING_SNAKE_CASE__       )
         self.assertEqual(SCREAMING_SNAKE_CASE__       ,     ["a", "c"]       )
         self.assertEqual(SCREAMING_SNAKE_CASE__       ,     [-3, -1]       )


    def        a				(	self					:					List[str]       )				->	str:
         # Stage names must be set
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              verify_out_features_out_indices(["a", "b"]       ,     (0, 1)       ,     SCREAMING_SNAKE_CASE__       )

         # Out features must be a list
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              verify_out_features_out_indices(("a", "b")       ,     (0, 1)       ,     ["a", "b"]       )

         # Out features must be a subset of stage names
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              verify_out_features_out_indices(["a", "b"]       ,     (0, 1)       ,     ["a"]       )

         # Out indices must be a list or tuple
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              verify_out_features_out_indices(SCREAMING_SNAKE_CASE__       ,     0       ,     ["a", "b"]       )

         # Out indices must be a subset of stage names
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              verify_out_features_out_indices(SCREAMING_SNAKE_CASE__       ,     (0, 1)       ,     ["a"]       )

         # Out features and out indices must be the same length
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              verify_out_features_out_indices(["a", "b"]       ,     (0,)       ,     ["a", "b", "c"]       )

         # Out features should match out indices
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              verify_out_features_out_indices(["a", "b"]       ,     (0, 2)       ,     ["a", "b", "c"]       )

         # Out features and out indices should be in order
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              verify_out_features_out_indices(["b", "a"]       ,     (0, 1)       ,     ["a", "b"]       )

         # Check passes with valid inputs
         verify_out_features_out_indices(["a", "b", "d"]       ,     (0, 1, -1)       ,     ["a", "b", "c", "d"]       )


    def        a				(	self					:					Optional[Any]       )				->	Optional[Any]:
         lowerCAmelCase__          =			BackboneMixin()

         lowerCAmelCase__          =			["a", "b", "c"]
         lowerCAmelCase__          =			["a", "c"]
         lowerCAmelCase__          =			[0, 2]

         # Check that the output features and indices are set correctly
         self.assertEqual(backbone.out_features       ,     ["a", "c"]       )
         self.assertEqual(backbone.out_indices       ,     [0, 2]       )

         # Check out features and indices are updated correctly
         lowerCAmelCase__          =			["a", "b"]
         self.assertEqual(backbone.out_features       ,     ["a", "b"]       )
         self.assertEqual(backbone.out_indices       ,     [0, 1]       )

         lowerCAmelCase__          =			[-3, -1]
         self.assertEqual(backbone.out_features       ,     ["a", "c"]       )
         self.assertEqual(backbone.out_indices       ,     [-3, -1]       )






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 			__lowerCamelCase	(   unittest.TestCase   ):




    """simple docstring"""

    snake_case__ =				MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING


    def        a				(	self					:					str       ,     SCREAMING_SNAKE_CASE__					:					Tuple       ,     SCREAMING_SNAKE_CASE__					:					List[str]       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]       )				->	Any:
         lowerCAmelCase__          =			hf_hub_download(
             repo_id="nateraw/video-demo"       ,     filename="archery.mp4"       ,     repo_type="dataset"       )
         lowerCAmelCase__          =			VideoClassificationPipeline(model=SCREAMING_SNAKE_CASE__       ,     image_processor=SCREAMING_SNAKE_CASE__       ,     top_k=2       )
         lowerCAmelCase__          =			[
             example_video_filepath,
             "https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4",
         ]
         return video_classifier, examples


    def        a				(	self					:					Any       ,     SCREAMING_SNAKE_CASE__					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]       )				->	Tuple:
         for example in examples:
              lowerCAmelCase__          =			video_classifier(SCREAMING_SNAKE_CASE__       )

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


    @require_torch
    def        a				(	self					:					Dict       )				->	Optional[Any]:
         lowerCAmelCase__          =			"hf-internal-testing/tiny-random-VideoMAEForVideoClassification"
         lowerCAmelCase__          =			VideoMAEFeatureExtractor(
             size={"shortest_edge": 10}       ,     crop_size={"height": 10, "width": 10}       )
         lowerCAmelCase__          =			pipeline(
             "video-classification"       ,     model=SCREAMING_SNAKE_CASE__       ,     feature_extractor=SCREAMING_SNAKE_CASE__       ,     frame_sampling_rate=4       )

         lowerCAmelCase__          =			hf_hub_download(repo_id="nateraw/video-demo"       ,     filename="archery.mp4"       ,     repo_type="dataset"       )
         lowerCAmelCase__          =			video_classifier(SCREAMING_SNAKE_CASE__       ,     top_k=2       )
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE__       ,     decimals=4       )       ,     [{"score": 0.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "label": "LABEL_1"}]       ,     )

         lowerCAmelCase__          =			video_classifier(
             [
                 video_file_path,
                 video_file_path,
             ]       ,     top_k=2       ,     )
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE__       ,     decimals=4       )       ,     [
                 [{"score": 0.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "label": "LABEL_1"}],
                 [{"score": 0.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "label": "LABEL_1"}],
             ]       ,     )


    @require_tf
    def        a				(	self					:					Optional[Any]       )				->	Optional[int]:
         pass
