Upload ViT-L event graph model
Browse files
README.md
CHANGED
|
@@ -6,80 +6,202 @@ tags:
|
|
| 6 |
- vjepa
|
| 7 |
- slot-attention
|
| 8 |
- pytorch
|
|
|
|
|
|
|
| 9 |
library_name: pytorch
|
| 10 |
pipeline_tag: video-classification
|
| 11 |
---
|
| 12 |
|
| 13 |
# Event Graph Generation — ViT-L
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
## Model Details
|
| 20 |
|
| 21 |
| 項目 | 値 |
|
| 22 |
|---|---|
|
| 23 |
-
| パラメータ数 | 15.0M |
|
| 24 |
| V-JEPA backbone | `vjepa2_1_vit_large_384` |
|
| 25 |
| V-JEPA hidden_size | 1024 |
|
| 26 |
-
| Object Pooling
|
| 27 |
-
| Event
|
| 28 |
| d_model | 256 |
|
| 29 |
| Action classes | 13 |
|
| 30 |
-
|
|
| 31 |
|
| 32 |
-
## Architecture
|
| 33 |
|
| 34 |
```
|
| 35 |
Video → V-JEPA 2.1 ViT-L → spatiotemporal tokens (B, S, 1024)
|
| 36 |
→ ObjectPoolingModule (Slot Attention, K=24 slots)
|
| 37 |
→ ObjectRepresentation (identity, trajectory, existence, categories)
|
| 38 |
-
→ VJEPAEventDecoder (M=20 event queries)
|
| 39 |
-
→
|
| 40 |
```
|
| 41 |
|
| 42 |
-
## Prediction Heads
|
| 43 |
|
| 44 |
| Head | Shape | Description |
|
| 45 |
|---|---|---|
|
| 46 |
-
| interaction | (M, 1) |
|
| 47 |
-
| action | (M, 13) |
|
| 48 |
-
| agent_ptr | (M, K) |
|
| 49 |
-
| target_ptr | (M, K) |
|
| 50 |
-
| source_ptr | (M, K+1) |
|
| 51 |
-
| dest_ptr | (M, K+1) |
|
| 52 |
-
| frame | (M, T) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
```python
|
| 57 |
import torch
|
|
|
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
# Build model
|
| 63 |
from event_graph_generation.config import Config
|
| 64 |
from event_graph_generation.models.base import build_model
|
| 65 |
|
| 66 |
-
config = Config.from_yaml(
|
| 67 |
model = build_model(config.model, vjepa_config=config.vjepa)
|
|
|
|
|
|
|
| 68 |
model.load_state_dict(state_dict)
|
| 69 |
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
```
|
| 71 |
|
| 72 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
-
|
| 77 |
-
-
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
## License
|
| 80 |
|
| 81 |
MIT License
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
## Links
|
| 84 |
|
| 85 |
- **Repository**: [ChanYu1224/event-graph-generation](https://github.com/ChanYu1224/event-graph-generation)
|
|
|
|
|
|
| 6 |
- vjepa
|
| 7 |
- slot-attention
|
| 8 |
- pytorch
|
| 9 |
+
- set-prediction
|
| 10 |
+
- hungarian-matching
|
| 11 |
library_name: pytorch
|
| 12 |
pipeline_tag: video-classification
|
| 13 |
---
|
| 14 |
|
| 15 |
# Event Graph Generation — ViT-L
|
| 16 |
|
| 17 |
+
## Model Overview
|
| 18 |
|
| 19 |
+
動画から構造化されたイベントグラフを予測するモデルです。動画中の「**誰が**・**何を**・**どこから**・**どこへ**」を構造化 JSON として出力します。
|
| 20 |
+
|
| 21 |
+
テキスト生成ではなく、DETR 風の**セット予測**(Hungarian Matching)により、イベントグラフを直接出力する設計です。
|
| 22 |
+
|
| 23 |
+
## Base Model
|
| 24 |
+
|
| 25 |
+
[V-JEPA 2.1](https://github.com/facebookresearch/vjepa) ViT-L (`vjepa2_1_vit_large_384`) を映像特徴抽出のバックボーンとして使用しています。V-JEPA は Meta が開発した自己教師あり映像表現学習モデルで、時空間トークンを出力します。
|
| 26 |
+
|
| 27 |
+
本モデル(Event Decoder 部分)は V-JEPA の出力トークンを入力とし、Object Pooling と Event Decoder の 2 段階でイベントグラフを予測します。V-JEPA 自体の重みは本チェックポイントに**含まれません**(別途 PyTorch Hub からロードされます)。
|
| 28 |
|
| 29 |
## Model Details
|
| 30 |
|
| 31 |
| 項目 | 値 |
|
| 32 |
|---|---|
|
| 33 |
+
| パラメータ数 (Event Decoder) | **15.0M** |
|
| 34 |
| V-JEPA backbone | `vjepa2_1_vit_large_384` |
|
| 35 |
| V-JEPA hidden_size | 1024 |
|
| 36 |
+
| Object Pooling | Slot Attention (K=24 slots, 3 iterations) |
|
| 37 |
+
| Event Decoder | DETR 風 cross-attention (M=20 event queries) |
|
| 38 |
| d_model | 256 |
|
| 39 |
| Action classes | 13 |
|
| 40 |
+
| Best epoch | 33 |
|
| 41 |
|
| 42 |
+
### Architecture
|
| 43 |
|
| 44 |
```
|
| 45 |
Video → V-JEPA 2.1 ViT-L → spatiotemporal tokens (B, S, 1024)
|
| 46 |
→ ObjectPoolingModule (Slot Attention, K=24 slots)
|
| 47 |
→ ObjectRepresentation (identity, trajectory, existence, categories)
|
| 48 |
+
→ VJEPAEventDecoder (M=20 event queries, cross-attention)
|
| 49 |
+
→ 7 Prediction Heads → EventGraph JSON
|
| 50 |
```
|
| 51 |
|
| 52 |
+
### Prediction Heads
|
| 53 |
|
| 54 |
| Head | Shape | Description |
|
| 55 |
|---|---|---|
|
| 56 |
+
| interaction | (M, 1) | イベントが有効か (BCE) |
|
| 57 |
+
| action | (M, 13) | アクション分類 (13 クラス) |
|
| 58 |
+
| agent_ptr | (M, K) | 行為者スロットへのポインタ |
|
| 59 |
+
| target_ptr | (M, K) | 対象スロットへのポインタ |
|
| 60 |
+
| source_ptr | (M, K+1) | 取り出し元へのポインタ (最後 = "none") |
|
| 61 |
+
| dest_ptr | (M, K+1) | 格納先へのポインタ (最後 = "none") |
|
| 62 |
+
| frame | (M, T) | イベント発生フレーム |
|
| 63 |
+
|
| 64 |
+
## Training
|
| 65 |
+
|
| 66 |
+
### Fine-tuning
|
| 67 |
+
|
| 68 |
+
- **ファインチューニング**: あり(V-JEPA backbone は frozen、Event Decoder 部分のみ学習)
|
| 69 |
+
- **学習手法**: Full fine-tuning(Event Decoder 全体を学習。LoRA 等は未使用)
|
| 70 |
+
- **Optimizer**: adamw (lr=0.0001, weight_decay=0.0001)
|
| 71 |
+
- **Scheduler**: cosine_warmup (warmup 5 epochs)
|
| 72 |
+
- **Early stopping**: patience=15
|
| 73 |
+
- **AMP**: bfloat16 mixed precision
|
| 74 |
+
- **損失関数**: Hungarian Matching によるセット予測損失
|
| 75 |
+
|
| 76 |
+
**Loss weights:**
|
| 77 |
+
|
| 78 |
+
| Component | Weight |
|
| 79 |
+
|---|---|
|
| 80 |
+
| interaction | 2.0 |
|
| 81 |
+
| action | 1.0 |
|
| 82 |
+
| agent_ptr | 1.0 |
|
| 83 |
+
| target_ptr | 1.0 |
|
| 84 |
+
| source_ptr | 0.5 |
|
| 85 |
+
| dest_ptr | 0.5 |
|
| 86 |
+
| frame | 0.5 |
|
| 87 |
+
|
| 88 |
+
### Training Data
|
| 89 |
+
|
| 90 |
+
- **データ**: 室内環境の録画動画(デスク・キッチン・部屋)
|
| 91 |
+
- **アノテーション**: Qwen 3.5 VLM による合成アノテーション(人手ラベルなし)
|
| 92 |
+
- **フレームレート**: 1 FPS でサンプリング、16 フレーム/クリップ、50% オーバーラップ
|
| 93 |
+
- **オブジェクトカテゴリ**: 28 カテゴリ + unknown(person, hand, chair, desk, laptop, monitor 等)
|
| 94 |
+
- **アクション語彙**: 13 クラス(take_out, put_in, place_on, pick_up, hand_over, open, close, use, move, attach, detach, inspect, no_event)
|
| 95 |
+
|
| 96 |
+
## Intended Use
|
| 97 |
+
|
| 98 |
+
### Intended Use Cases
|
| 99 |
+
|
| 100 |
+
- 製造・組立作業の動画からの作業イベント自動抽出
|
| 101 |
+
- 室内行動の構造的記録(誰が何をどこに置いたか等)
|
| 102 |
+
- 動画理解研究のための構造化アノテーション自動生成
|
| 103 |
+
- IoT / スマートホーム環境での行動ログ生成
|
| 104 |
|
| 105 |
+
### Out-of-Scope Use
|
| 106 |
+
|
| 107 |
+
- 個人の監視・追跡を目的とした利用
|
| 108 |
+
- 屋外・交通・医療など、学習データに含まれないドメインでの高精度な利用
|
| 109 |
+
- リアルタイム処理が必要なシステム(V-JEPA backbone の推論コストが高い)
|
| 110 |
+
- セキュリティ判断や法的判断の根拠としての利用
|
| 111 |
+
|
| 112 |
+
## Evaluation
|
| 113 |
+
|
| 114 |
+
本モデルは以下のメトリクスで評価されています:
|
| 115 |
+
|
| 116 |
+
| Metric | Description |
|
| 117 |
+
|---|---|
|
| 118 |
+
| event_detection_mAP | イベント検出の平均適合率 |
|
| 119 |
+
| action_accuracy | アクション分類精度 |
|
| 120 |
+
| pointer_accuracy | agent/target ポインタの正解率 |
|
| 121 |
+
| frame_mae | イベントフレーム予測の平均絶対誤差 |
|
| 122 |
+
| graph_f1 | EventGraph 全体の F1 スコア |
|
| 123 |
+
|
| 124 |
+
> **注意**: 本モデルは VLM 合成アノテーションで学習されており、人手アノテーションによるベンチマークスコアは未計測です。
|
| 125 |
+
|
| 126 |
+
## Inference
|
| 127 |
+
|
| 128 |
+
### End-to-End Inference (推奨)
|
| 129 |
+
|
| 130 |
+
```bash
|
| 131 |
+
# リポジトリをクローン
|
| 132 |
+
git clone https://github.com/ChanYu1224/event-graph-generation.git
|
| 133 |
+
cd event-graph-generation
|
| 134 |
+
uv sync
|
| 135 |
+
|
| 136 |
+
# 推論実行
|
| 137 |
+
uv run python scripts/6_run_inference.py \
|
| 138 |
+
--video your_video.mp4 \
|
| 139 |
+
--checkpoint path/to/model.pt \
|
| 140 |
+
--config configs/vjepa_training.yaml \
|
| 141 |
+
--vjepa-config configs/vjepa.yaml \
|
| 142 |
+
--output output/event_graph.json
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
### Python API
|
| 146 |
|
| 147 |
```python
|
| 148 |
import torch
|
| 149 |
+
from huggingface_hub import hf_hub_download
|
| 150 |
|
| 151 |
+
# Download model
|
| 152 |
+
model_path = hf_hub_download(repo_id="Yuchn/event-graph-vitl", filename="model.pt")
|
| 153 |
+
config_path = hf_hub_download(repo_id="Yuchn/event-graph-vitl", filename="config.yaml")
|
| 154 |
|
| 155 |
+
# Build model
|
| 156 |
from event_graph_generation.config import Config
|
| 157 |
from event_graph_generation.models.base import build_model
|
| 158 |
|
| 159 |
+
config = Config.from_yaml(config_path)
|
| 160 |
model = build_model(config.model, vjepa_config=config.vjepa)
|
| 161 |
+
|
| 162 |
+
state_dict = torch.load(model_path, map_location="cpu")
|
| 163 |
model.load_state_dict(state_dict)
|
| 164 |
model.eval()
|
| 165 |
+
|
| 166 |
+
# Forward pass (vjepa_tokens: pre-extracted V-JEPA features)
|
| 167 |
+
# vjepa_tokens shape: (batch_size, num_tokens, hidden_size)
|
| 168 |
+
with torch.no_grad():
|
| 169 |
+
obj_repr, predictions = model(vjepa_tokens)
|
| 170 |
```
|
| 171 |
|
| 172 |
+
## Limitations
|
| 173 |
+
|
| 174 |
+
### Bias
|
| 175 |
+
|
| 176 |
+
- 学習データは室内環境(デスク・キッチン・部屋)に限定されており、屋外や工場環境での精度は未検証
|
| 177 |
+
- VLM 合成アノテーションに依存しているため、Qwen 3.5 のバイアスを継承する可能性がある
|
| 178 |
+
- オブジェクトカテゴリは 28 種類に限定されており、未知カテゴリのオブジェクトは "unknown" として扱われる
|
| 179 |
|
| 180 |
+
### Limitations
|
| 181 |
+
|
| 182 |
+
- V-JEPA backbone は frozen のため、ドメイン固有の映像表現への適応は限定的
|
| 183 |
+
- 13 種類のアクション語彙に限定されており、語彙外の行動は検出できない
|
| 184 |
+
- 1 FPS サンプリングのため、1 秒未満の高速なイベントは見逃す可能性がある
|
| 185 |
+
- 推論には CUDA 対応 GPU が必要(V-JEPA backbone + Event Decoder)
|
| 186 |
+
- 長時間動画ではスライディングウィンドウ処理のため、メモリ使用量と処理時間が線形に増加
|
| 187 |
|
| 188 |
## License
|
| 189 |
|
| 190 |
MIT License
|
| 191 |
|
| 192 |
+
## Citation
|
| 193 |
+
|
| 194 |
+
```bibtex
|
| 195 |
+
@software{event_graph_generation_2026,
|
| 196 |
+
title = {Event Graph Generation: Structured Event Prediction from Video},
|
| 197 |
+
author = {Yuchn},
|
| 198 |
+
year = {2026},
|
| 199 |
+
url = {https://github.com/ChanYu1224/event-graph-generation},
|
| 200 |
+
license = {MIT}
|
| 201 |
+
}
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
## Links
|
| 205 |
|
| 206 |
- **Repository**: [ChanYu1224/event-graph-generation](https://github.com/ChanYu1224/event-graph-generation)
|
| 207 |
+
- **V-JEPA**: [facebookresearch/vjepa](https://github.com/facebookresearch/vjepa)
|