|
| 1 | +<!--Copyright 2026 The HuggingFace Team. All rights reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +the License. You may obtain a copy of the License at |
| 5 | +
|
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +specific language governing permissions and limitations under the License. |
| 11 | +--> |
| 12 | +*This model was published in HF papers on 2024-02-20 and contributed to Hugging Face Transformers on 2026-06-19.* |
| 13 | + |
| 14 | +<div style="float: right;"> |
| 15 | + <div class="flex flex-wrap space-x-1"> |
| 16 | + <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"> |
| 17 | + </div> |
| 18 | +</div> |
| 19 | + |
| 20 | +# VideoPrism |
| 21 | + |
| 22 | +The VideoPrism model was proposed in the paper [VideoPrism: A Foundational Visual Encoder for Video Understanding](https://huggingface.co/papers/2402.13217) by Google DeepMind ([blog post](https://research.google/blog/videoprism-a-foundational-visual-encoder-for-video-understanding/)). |
| 23 | + |
| 24 | +VideoPrism is a general-purpose video encoder that tackles diverse video understanding tasks with a single frozen model. The model is pretrained on a large-scale heterogeneous corpus containing 36M high-quality video-caption pairs and 582M video clips with noisy parallel text (e.g., ASR transcripts). The pretraining approach improves upon masked autoencoding through global-local distillation of semantic video embeddings and a token shuffling scheme, enabling the model to focus primarily on the video modality while leveraging text associated with videos. VideoPrism achieves state-of-the-art performance on 31 out of 33 video understanding benchmarks across four broad task groups, from web video question answering to computer vision for science. |
| 25 | + |
| 26 | +<div class="flex justify-center"> |
| 27 | + <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/VideoPrism_Overview.jpeg" alt="drawing" width="600"/> |
| 28 | +</div> |
| 29 | + |
| 30 | +You can find all original VideoPrism checkpoints under the [VideoPrism](https://huggingface.co/collections/google/videoprism) collection. |
| 31 | + |
| 32 | +Notes: |
| 33 | + |
| 34 | +- VideoPrism uses a factorized spatio-temporal encoder architecture, processing videos through separate spatial and temporal transformers. |
| 35 | +- The model supports video-text contrastive learning through `VideoPrismClipModel`, which combines a video encoder and a text encoder. `VideoPrismConfig` must be used with this model. |
| 36 | +- For video classification tasks, use `VideoPrismForVideoClassification` which adds a classification head on top of the video encoder. `VideoPrismVisionConfig` must be used with this model. |
| 37 | +- The vision encoder can be used standalone via `VideoPrismVisionModel` for extracting video features. `VideoPrismVisionConfig` must be used with this model. |
| 38 | +- The default input resolution is 288x288 pixels with 16 frames per video clip for the base models and 8 frames for the large models. Set interpolate_pos_encoding=True to use the models with custom resolution and frames per clip. |
| 39 | + |
| 40 | +This model was contributed by [MHRDYN7](https://github.com/MHRDYN7) and reviewed by [vasqu](https://github.com/vasqu) & [zucchini-nlp](https://github.com/zucchini-nlp). |
| 41 | +The original code can be found [here](https://github.com/google-deepmind/videoprism). |
| 42 | + |
| 43 | + |
| 44 | +## Usage example |
| 45 | + |
| 46 | +The snippet below shows how to load the VideoPrismVisionModel for feature extraction using the `AutoModel` class. |
| 47 | + |
| 48 | +```py |
| 49 | +import torch |
| 50 | +from transformers import AutoModel, AutoVideoProcessor |
| 51 | + |
| 52 | +processor = AutoVideoProcessor.from_pretrained("google/videoprism-base-f16r288", revision="refs/pr/4") |
| 53 | +model = AutoModel.from_pretrained( |
| 54 | + "google/videoprism-base-f16r288", |
| 55 | + revision="refs/pr/4", |
| 56 | + device_map="auto", |
| 57 | + # use "flash_attention_2" for faster inference on supported hardware |
| 58 | + # attn_implementation="flash_attention_2" |
| 59 | +) |
| 60 | + |
| 61 | +video_url = "https://huggingface.co/datasets/nateraw/kinetics-mini/resolve/main/val/archery/-Qz25rXdMjE_000014_000024.mp4" |
| 62 | + |
| 63 | +# when do_sample_frames=True, 16/8 frames will be sampled by default depending on the checkpoint size base/large. |
| 64 | +processed_video_inputs = processor(videos=[video_url], return_metadata=True, do_sample_frames=True) |
| 65 | +video_metadata = processed_video_inputs["video_metadata"] |
| 66 | +video_inputs = processed_video_inputs["pixel_values_videos"].to(model.device) |
| 67 | +outputs = model(video_inputs) |
| 68 | + |
| 69 | +# VideoPrism encoder outputs |
| 70 | +encoder_outputs = outputs.last_hidden_state |
| 71 | + |
| 72 | +``` |
| 73 | + |
| 74 | + |
| 75 | +## VideoPrismVisionConfig |
| 76 | + |
| 77 | +[[autodoc]] VideoPrismVisionConfig |
| 78 | + |
| 79 | +## VideoPrismTextConfig |
| 80 | + |
| 81 | +[[autodoc]] VideoPrismTextConfig |
| 82 | + |
| 83 | +## VideoPrismConfig |
| 84 | + |
| 85 | +[[autodoc]] VideoPrismConfig |
| 86 | + |
| 87 | +## VideoPrismTokenizer |
| 88 | + |
| 89 | +[[autodoc]] VideoPrismTokenizer |
| 90 | + |
| 91 | +## VideoPrismProcessor |
| 92 | + |
| 93 | +[[autodoc]] VideoPrismProcessor |
| 94 | + |
| 95 | +## VideoPrismVisionModel |
| 96 | + |
| 97 | +[[autodoc]] VideoPrismVisionModel |
| 98 | + - forward |
| 99 | + |
| 100 | +## VideoPrismVideoModel |
| 101 | + |
| 102 | +[[autodoc]] VideoPrismVideoModel |
| 103 | + - forward |
| 104 | + |
| 105 | +## VideoPrismTextModel |
| 106 | + |
| 107 | +[[autodoc]] VideoPrismTextModel |
| 108 | + - forward |
| 109 | + |
| 110 | +## VideoPrismClipModel |
| 111 | + |
| 112 | +[[autodoc]] VideoPrismClipModel |
| 113 | + - forward |
| 114 | + |
| 115 | +## VideoPrismForVideoClassification |
| 116 | + |
| 117 | +[[autodoc]] VideoPrismForVideoClassification |
| 118 | + - forward |
0 commit comments