



'''simple docstring'''






import unittest

import torch

from diffusers import VQModel
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()



class 							lowercase       (  _lowerCamelCase					,					_lowerCamelCase					,					unittest.TestCase				):


 """simple docstring"""


 UpperCAmelCase							=  VQModel
 UpperCAmelCase							=  "sample"







 @property
 def _snake_case (							self  ,a_=(32, 32)							)		->   Dict:
        _UpperCAmelCase  :						List[str]			     = 4
        _UpperCAmelCase  :						int			     = 3

        _UpperCAmelCase  :						Optional[Any]			     = floats_tensor((batch_size, num_channels) + sizes							).to(snake_case__							)

        return {"sample": image}







 @property
 def _snake_case (							self							)		->   str:
        return (3, 32, 32)







 @property
 def _snake_case (							self							)		->   int:
        return (3, 32, 32)







 def _snake_case (							self							)		->   str:
        _UpperCAmelCase  :						Optional[int]			     = {
            "block_out_channels": [32, 64],
            "in_channels": 3,
            "out_channels": 3,
            "down_block_types": ["DownEncoderBlock2D", "DownEncoderBlock2D"],
            "up_block_types": ["UpDecoderBlock2D", "UpDecoderBlock2D"],
            "latent_channels": 3,
        }
        _UpperCAmelCase  :						List[str]			     = self.dummy_input
        return init_dict, inputs_dict







 def _snake_case (							self							)		->   Dict:
        pass







 def _snake_case (							self							)		->   Dict:
        pass







 def _snake_case (							self							)		->   Union[str, Any]:
        _UpperCAmelCase  :						Optional[int]			     = VQModel.from_pretrained("""fusing/vqgan-dummy"""  ,output_loading_info=snake_case__							)
        self.assertIsNotNone(snake_case__							)
        self.assertEqual(len(loading_info["""missing_keys"""]							)  ,0							)

        model.to(snake_case__							)
        _UpperCAmelCase  :						Optional[int]			     = model(**self.dummy_input							)

        assert image is not None, "Make sure output is not None"







 def _snake_case (							self							)		->   Optional[int]:
        _UpperCAmelCase  :						Union[str, Any]			     = VQModel.from_pretrained("""fusing/vqgan-dummy"""							)
        model.to(snake_case__							).eval()

        torch.manual_seed(0							)
        if torch.cuda.is_available():
               torch.cuda.manual_seed_all(0							)

        _UpperCAmelCase  :						List[str]			     = torch.randn(1  ,model.config.in_channels  ,model.config.sample_size  ,model.config.sample_size							)
        _UpperCAmelCase  :						Union[str, Any]			     = image.to(snake_case__							)
        with torch.no_grad():
               _UpperCAmelCase  :						int			     = model(snake_case__							).sample

        _UpperCAmelCase  :						Any			     = output[0, -1, -3:, -3:].flatten().cpu()
        # fmt: off
        _UpperCAmelCase  :						Tuple			     = torch.tensor([-0.0153, -0.4044, -0.1880, -0.5161, -0.2418, -0.4072, -0.1612, -0.0633, -0.0143]							)
        # fmt: on
        self.assertTrue(torch.allclose(snake_case__  ,snake_case__  ,atol=1E-3							)							)







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





