Commit
·
995ed01
0
Parent(s):
Initial commit
Browse files- .gitattributes +35 -0
- README.md +86 -0
- config.json +33 -0
- model.safetensors +3 -0
- notebook.ipynb +157 -0
- original/model.pth +3 -0
- video_preprocessor_config.json +71 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
pipeline_tag: video-classification
|
4 |
+
tags:
|
5 |
+
- video
|
6 |
+
---
|
7 |
+
|
8 |
+
# V-JEPA 2
|
9 |
+
|
10 |
+
A frontier video understanding model developed by FAIR, Meta, which extends the pretraining objectives of [VJEPA](https://ai.meta.com/blog/v-jepa-yann-lecun-ai-model-video-joint-embedding-predictive-architecture/), resulting in state-of-the-art video understanding capabilities, leveraging data and model sizes at scale.
|
11 |
+
The code is released [in this repository](https://github.com/facebookresearch/vjepa2).
|
12 |
+
|
13 |
+
<img src="https://dl.fbaipublicfiles.com/vjepa2/vjepa2-pretrain.gif">
|
14 |
+
|
15 |
+
## Installation
|
16 |
+
|
17 |
+
To run V-JEPA 2 model, ensure you have installed the latest transformers:
|
18 |
+
|
19 |
+
```bash
|
20 |
+
pip install -U git+https://github.com/huggingface/transformers
|
21 |
+
```
|
22 |
+
|
23 |
+
## Intended Uses
|
24 |
+
|
25 |
+
V-JEPA 2 is intended to represent any video (and image) to perform video classification, retrieval, or as a video encoder for VLMs.
|
26 |
+
|
27 |
+
```python
|
28 |
+
from transformers import AutoVideoProcessor, AutoModel
|
29 |
+
|
30 |
+
hf_repo = "facebook/vjepa2-vitl-fpc64-256"
|
31 |
+
|
32 |
+
model = AutoModel.from_pretrained(hf_repo)
|
33 |
+
processor = AutoVideoProcessor.from_pretrained(hf_repo)
|
34 |
+
```
|
35 |
+
|
36 |
+
To load a video, sample the number of frames according to the model. For this model, we use 64.
|
37 |
+
|
38 |
+
```python
|
39 |
+
import torch
|
40 |
+
from torchcodec.decoders import VideoDecoder
|
41 |
+
import numpy as np
|
42 |
+
|
43 |
+
video_url = "https://huggingface.co/datasets/nateraw/kinetics-mini/resolve/main/val/archery/-Qz25rXdMjE_000014_000024.mp4"
|
44 |
+
vr = VideoDecoder(video_url)
|
45 |
+
frame_idx = np.arange(0, 64) # choosing some frames. here, you can define more complex sampling strategy
|
46 |
+
video = vr.get_frames_at(indices=frame_idx).data # T x C x H x W
|
47 |
+
video = processor(video, return_tensors="pt").to(model.device)
|
48 |
+
with torch.no_grad():
|
49 |
+
video_embeddings = model.get_vision_features(**video)
|
50 |
+
|
51 |
+
print(video_embeddings.shape)
|
52 |
+
```
|
53 |
+
|
54 |
+
To load an image, simply copy the image to the desired number of frames.
|
55 |
+
|
56 |
+
```python
|
57 |
+
from transformers.image_utils import load_image
|
58 |
+
|
59 |
+
image = load_image("https://huggingface.co/datasets/merve/coco/resolve/main/val2017/000000000285.jpg")
|
60 |
+
pixel_values = processor(image, return_tensors="pt").to(model.device)["pixel_values_videos"]
|
61 |
+
pixel_values = pixel_values.repeat(1, 16, 1, 1, 1) # repeating image 16 times
|
62 |
+
|
63 |
+
with torch.no_grad():
|
64 |
+
image_embeddings = model.get_vision_features(pixel_values)
|
65 |
+
|
66 |
+
print(image_embeddings.shape)
|
67 |
+
```
|
68 |
+
|
69 |
+
For more code examples, please refer to the V-JEPA 2 documentation.
|
70 |
+
|
71 |
+
|
72 |
+
### Citation
|
73 |
+
|
74 |
+
```
|
75 |
+
@techreport{assran2025vjepa2,
|
76 |
+
title={V-JEPA~2: Self-Supervised Video Models Enable Understanding, Prediction and Planning},
|
77 |
+
author={Assran, Mahmoud and Bardes, Adrien and Fan, David and Garrido, Quentin and Howes, Russell and
|
78 |
+
Komeili, Mojtaba and Muckley, Matthew and Rizvi, Ammar and Roberts, Claire and Sinha, Koustuv and Zholus, Artem and
|
79 |
+
Arnaud, Sergio and Gejji, Abha and Martin, Ada and Robert Hogan, Francois and Dugas, Daniel and
|
80 |
+
Bojanowski, Piotr and Khalidov, Vasil and Labatut, Patrick and Massa, Francisco and Szafraniec, Marc and
|
81 |
+
Krishnakumar, Kapil and Li, Yong and Ma, Xiaodong and Chandar, Sarath and Meier, Franziska and LeCun, Yann and
|
82 |
+
Rabbat, Michael and Ballas, Nicolas},
|
83 |
+
institution={FAIR at Meta},
|
84 |
+
year={2025}
|
85 |
+
}
|
86 |
+
```
|
config.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"VJEPA2Model"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.0,
|
6 |
+
"crop_size": 256,
|
7 |
+
"drop_path_rate": 0.0,
|
8 |
+
"frames_per_clip": 64,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.0,
|
11 |
+
"hidden_size": 1024,
|
12 |
+
"image_size": 256,
|
13 |
+
"in_chans": 3,
|
14 |
+
"initializer_range": 0.02,
|
15 |
+
"layer_norm_eps": 1e-06,
|
16 |
+
"mlp_ratio": 4,
|
17 |
+
"model_type": "vjepa2",
|
18 |
+
"num_attention_heads": 16,
|
19 |
+
"num_hidden_layers": 24,
|
20 |
+
"patch_size": 16,
|
21 |
+
"pred_hidden_size": 384,
|
22 |
+
"pred_mlp_ratio": 4.0,
|
23 |
+
"pred_num_attention_heads": 12,
|
24 |
+
"pred_num_hidden_layers": 12,
|
25 |
+
"pred_num_mask_tokens": 10,
|
26 |
+
"pred_zero_init_mask_tokens": true,
|
27 |
+
"qkv_bias": true,
|
28 |
+
"torch_dtype": "float32",
|
29 |
+
"transformers_version": "4.53.0.dev0",
|
30 |
+
"tubelet_size": 2,
|
31 |
+
"use_SiLU": false,
|
32 |
+
"wide_SiLU": true
|
33 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:25466aef85727d16546c6cf8c99f12fcfad9cbca8225d45f23685e2e025b786b
|
3 |
+
size 1303947864
|
notebook.ipynb
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"gpuType": "T4"
|
8 |
+
},
|
9 |
+
"kernelspec": {
|
10 |
+
"name": "python3",
|
11 |
+
"display_name": "Python 3"
|
12 |
+
},
|
13 |
+
"language_info": {
|
14 |
+
"name": "python"
|
15 |
+
},
|
16 |
+
"accelerator": "GPU"
|
17 |
+
},
|
18 |
+
"cells": [
|
19 |
+
{
|
20 |
+
"cell_type": "markdown",
|
21 |
+
"source": [
|
22 |
+
"# Use VJEPA 2"
|
23 |
+
],
|
24 |
+
"metadata": {
|
25 |
+
"id": "02ruu54h4yLc"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"cell_type": "markdown",
|
30 |
+
"source": [
|
31 |
+
"V-JEPA 2 is a new open 1.2B video embedding model by Meta, which attempts to capture the physical world modelling through video ⏯️\n",
|
32 |
+
"\n",
|
33 |
+
"The model can be used for various tasks for video: fine-tuning for downstream tasks like video classification, or any task involving embeddings (similarity, retrieval and more!).\n",
|
34 |
+
"\n",
|
35 |
+
"You can check all V-JEPA 2 checkpoints and the datasets that come with this release [in this collection](https://huggingface.co/collections/facebook/v-jepa-2-6841bad8413014e185b497a6)."
|
36 |
+
],
|
37 |
+
"metadata": {
|
38 |
+
"id": "ol0IGYCd4hg4"
|
39 |
+
}
|
40 |
+
},
|
41 |
+
{
|
42 |
+
"cell_type": "markdown",
|
43 |
+
"source": [
|
44 |
+
"We need to install transformers' release specific branch."
|
45 |
+
],
|
46 |
+
"metadata": {
|
47 |
+
"id": "kIIBxYOA41Ga"
|
48 |
+
}
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"cell_type": "code",
|
52 |
+
"source": [
|
53 |
+
"!pip install -q git+https://github.com/huggingface/[email protected]"
|
54 |
+
],
|
55 |
+
"metadata": {
|
56 |
+
"id": "4D4D1hC940yX"
|
57 |
+
},
|
58 |
+
"execution_count": null,
|
59 |
+
"outputs": []
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"cell_type": "code",
|
63 |
+
"source": [
|
64 |
+
"from huggingface_hub import login # to later push the model\n",
|
65 |
+
"\n",
|
66 |
+
"login()"
|
67 |
+
],
|
68 |
+
"metadata": {
|
69 |
+
"id": "Ne2rU68Ep1On"
|
70 |
+
},
|
71 |
+
"execution_count": null,
|
72 |
+
"outputs": []
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"cell_type": "markdown",
|
76 |
+
"source": [
|
77 |
+
"As of now, Colab supports torchcodec==0.2.1 which supports torch==2.6.0."
|
78 |
+
],
|
79 |
+
"metadata": {
|
80 |
+
"id": "dJWXmFu53Ap6"
|
81 |
+
}
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"cell_type": "code",
|
85 |
+
"source": [
|
86 |
+
"!pip install -q torch==2.6.0 torchvision==0.21.0\n",
|
87 |
+
"!pip install -q torchcodec==0.2.1\n",
|
88 |
+
"\n",
|
89 |
+
"import torch\n",
|
90 |
+
"print(\"Torch:\", torch.__version__)\n",
|
91 |
+
"from torchcodec.decoders import VideoDecoder # verify"
|
92 |
+
],
|
93 |
+
"metadata": {
|
94 |
+
"id": "JIoq84ze2_Ls"
|
95 |
+
},
|
96 |
+
"execution_count": null,
|
97 |
+
"outputs": []
|
98 |
+
},
|
99 |
+
{
|
100 |
+
"cell_type": "markdown",
|
101 |
+
"source": [
|
102 |
+
"## Initialize the model and the processor"
|
103 |
+
],
|
104 |
+
"metadata": {
|
105 |
+
"id": "-7OATf5S20U_"
|
106 |
+
}
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"cell_type": "code",
|
110 |
+
"source": [
|
111 |
+
"from transformers import AutoVideoProcessor, AutoModel\n",
|
112 |
+
"\n",
|
113 |
+
"hf_repo = \"facebook/vjepa2-vitl-fpc64-256\"\n",
|
114 |
+
"\n",
|
115 |
+
"model = AutoModel.from_pretrained(hf_repo).to(\"cuda\")\n",
|
116 |
+
"processor = AutoVideoProcessor.from_pretrained(hf_repo)"
|
117 |
+
],
|
118 |
+
"metadata": {
|
119 |
+
"id": "K8oSsy7Y2zQK"
|
120 |
+
},
|
121 |
+
"execution_count": null,
|
122 |
+
"outputs": []
|
123 |
+
},
|
124 |
+
{
|
125 |
+
"cell_type": "markdown",
|
126 |
+
"source": [
|
127 |
+
"## Extract video embeddings from the model"
|
128 |
+
],
|
129 |
+
"metadata": {
|
130 |
+
"id": "ZJ_DUR9f22Uc"
|
131 |
+
}
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"cell_type": "code",
|
135 |
+
"source": [
|
136 |
+
"import torch\n",
|
137 |
+
"from torchcodec.decoders import VideoDecoder\n",
|
138 |
+
"import numpy as np\n",
|
139 |
+
"\n",
|
140 |
+
"video_url = \"https://huggingface.co/datasets/nateraw/kinetics-mini/resolve/main/val/archery/-Qz25rXdMjE_000014_000024.mp4\"\n",
|
141 |
+
"vr = VideoDecoder(video_url)\n",
|
142 |
+
"frame_idx = np.arange(0, 64) # choosing some frames. here, you can define more complex sampling strategy\n",
|
143 |
+
"video = vr.get_frames_at(indices=frame_idx).data # T x C x H x W\n",
|
144 |
+
"video = processor(video, return_tensors=\"pt\").to(model.device)\n",
|
145 |
+
"with torch.no_grad():\n",
|
146 |
+
" video_embeddings = model.get_vision_features(**video)\n",
|
147 |
+
"\n",
|
148 |
+
"print(video_embeddings.shape)"
|
149 |
+
],
|
150 |
+
"metadata": {
|
151 |
+
"id": "kAgWZJHt24px"
|
152 |
+
},
|
153 |
+
"execution_count": null,
|
154 |
+
"outputs": []
|
155 |
+
}
|
156 |
+
]
|
157 |
+
}
|
original/model.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5346856ec9df69487fe72a25bf2632aaa8112df33fb67708e3f7374edc1f7012
|
3 |
+
size 5127726842
|
video_preprocessor_config.json
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_valid_kwargs_names": [
|
3 |
+
"do_convert_rgb",
|
4 |
+
"do_resize",
|
5 |
+
"size",
|
6 |
+
"size_divisor",
|
7 |
+
"default_to_square",
|
8 |
+
"resample",
|
9 |
+
"do_rescale",
|
10 |
+
"rescale_factor",
|
11 |
+
"do_normalize",
|
12 |
+
"image_mean",
|
13 |
+
"image_std",
|
14 |
+
"do_pad",
|
15 |
+
"do_center_crop",
|
16 |
+
"crop_size",
|
17 |
+
"data_format",
|
18 |
+
"input_data_format",
|
19 |
+
"device"
|
20 |
+
],
|
21 |
+
"crop_size": {
|
22 |
+
"height": 256,
|
23 |
+
"width": 256
|
24 |
+
},
|
25 |
+
"data_format": "channels_first",
|
26 |
+
"default_to_square": true,
|
27 |
+
"device": null,
|
28 |
+
"do_center_crop": true,
|
29 |
+
"do_convert_rgb": null,
|
30 |
+
"do_normalize": true,
|
31 |
+
"do_pad": null,
|
32 |
+
"do_rescale": true,
|
33 |
+
"do_resize": true,
|
34 |
+
"image_mean": [
|
35 |
+
0.485,
|
36 |
+
0.456,
|
37 |
+
0.406
|
38 |
+
],
|
39 |
+
"image_std": [
|
40 |
+
0.229,
|
41 |
+
0.224,
|
42 |
+
0.225
|
43 |
+
],
|
44 |
+
"input_data_format": null,
|
45 |
+
"model_valid_processing_keys": [
|
46 |
+
"do_convert_rgb",
|
47 |
+
"do_resize",
|
48 |
+
"size",
|
49 |
+
"size_divisor",
|
50 |
+
"default_to_square",
|
51 |
+
"resample",
|
52 |
+
"do_rescale",
|
53 |
+
"rescale_factor",
|
54 |
+
"do_normalize",
|
55 |
+
"image_mean",
|
56 |
+
"image_std",
|
57 |
+
"do_pad",
|
58 |
+
"do_center_crop",
|
59 |
+
"crop_size",
|
60 |
+
"data_format",
|
61 |
+
"input_data_format",
|
62 |
+
"device"
|
63 |
+
],
|
64 |
+
"resample": 2,
|
65 |
+
"rescale_factor": 0.00392156862745098,
|
66 |
+
"size": {
|
67 |
+
"shortest_edge": 292
|
68 |
+
},
|
69 |
+
"size_divisor": null,
|
70 |
+
"video_processor_type": "VJEPA2VideoProcessor"
|
71 |
+
}
|