Views
No views yet

pip install -U git+https://github.com/huggingface/transformers1import torch
2import numpy as np
3
4from torchcodec.decoders import VideoDecoder
5from transformers import AutoVideoProcessor, AutoModelForVideoClassification
6
7device = "cuda" if torch.cuda.is_available() else "cpu"
8
9# Load model and video preprocessor
10hf_repo = "facebook/vjepa2-vitl-fpc32-256-diving48"
11
12model = AutoModelForVideoClassification.from_pretrained(hf_repo).to(device)
13processor = AutoVideoProcessor.from_pretrained(hf_repo)
14
15# To load a video, sample the number of frames according to the model.
16video_url = "https://huggingface.co/facebook/vjepa2-vitl-fpc32-256-diving48/resolve/main/sample/diving.mp4"
17vr = VideoDecoder(video_url)
18frame_idx = np.arange(0, model.config.frames_per_clip, 8) # you can define more complex sampling strategy
19video = vr.get_frames_at(indices=frame_idx).data # frames x channels x height x width
20
21# Preprocess and run inference
22inputs = processor(video, return_tensors="pt").to(model.device)
23with torch.no_grad():
24 outputs = model(**inputs)
25logits = outputs.logits
26
27print("Top 5 predicted class names:")
28top5_indices = logits.topk(5).indices[0]
29top5_probs = torch.softmax(logits, dim=-1).topk(5).values[0]
30for idx, prob in zip(top5_indices, top5_probs):
31 text_label = model.config.id2label[idx.item()]
32 print(f" - {text_label}: {prob:.2f}")Top 5 predicted class names:
- ['Reverse', 'Dive', 'NoTwis', 'PIKE']: 0.52
- ['Inward', '25som', 'NoTwis', 'PIKE']: 0.12
- ['Forward', '35som', 'NoTwis', 'PIKE']: 0.07
- ['Reverse', '25som', 'NoTwis', 'PIKE']: 0.05
- ['Forward', '25som', '1Twis', 'PIKE']: 0.03@techreport{assran2025vjepa2,
title={V-JEPA~2: Self-Supervised Video Models Enable Understanding, Prediction and Planning},
author={Assran, Mahmoud and Bardes, Adrien and Fan, David and Garrido, Quentin and Howes, Russell and
Komeili, Mojtaba and Muckley, Matthew and Rizvi, Ammar and Roberts, Claire and Sinha, Koustuv and Zholus, Artem and
Arnaud, Sergio and Gejji, Abha and Martin, Ada and Robert Hogan, Francois and Dugas, Daniel and
Bojanowski, Piotr and Khalidov, Vasil and Labatut, Patrick and Massa, Francisco and Szafraniec, Marc and
Krishnakumar, Kapil and Li, Yong and Ma, Xiaodong and Chandar, Sarath and Meier, Franziska and LeCun, Yann and
Rabbat, Michael and Ballas, Nicolas},
institution={FAIR at Meta},
year={2025}
}