Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- video-classification
|
| 5 |
+
- action-recognition
|
| 6 |
+
- vision-transformer
|
| 7 |
+
- hmdb51
|
| 8 |
+
- pytorch
|
| 9 |
+
datasets:
|
| 10 |
+
- hmdb51
|
| 11 |
+
library_name: pytorch
|
| 12 |
+
pipeline_tag: video-classification
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# LS-ViT for HMDB51 Action Recognition
|
| 16 |
+
|
| 17 |
+
LS-ViT (Long-Short ViT) is a ViT-Base backbone augmented with two motion-aware
|
| 18 |
+
modules for video action recognition:
|
| 19 |
+
|
| 20 |
+
- **SMIFModule** — *Short-term Motion Injection & Fusion*. Operates on raw RGB
|
| 21 |
+
frames, computes a windowed motion map across neighboring frames, and fuses
|
| 22 |
+
it back into the spatial features via a 1×1 convolution and a learned blend.
|
| 23 |
+
- **LMIModule** — *Long-term Motion Interaction*. Inserted inside every
|
| 24 |
+
transformer block. Operates on patch tokens by computing forward/backward
|
| 25 |
+
temporal differences in a reduced space and using them as a token-level
|
| 26 |
+
attention gate.
|
| 27 |
+
|
| 28 |
+
The backbone is initialized from `vit_base_patch16_224` (timm) and the full
|
| 29 |
+
model is fine-tuned on HMDB51 for 51-way action classification.
|
| 30 |
+
|
| 31 |
+
## Files
|
| 32 |
+
|
| 33 |
+
| File | Description |
|
| 34 |
+
| --- | --- |
|
| 35 |
+
| `lsvit_hmdb51_best.pt` | Best checkpoint by validation accuracy. State dict under key `"model"`. |
|
| 36 |
+
| `modeling.py` | Self-contained model architecture (no `timm` runtime dependency). |
|
| 37 |
+
| `README.md` | This card. |
|
| 38 |
+
|
| 39 |
+
## Training setup
|
| 40 |
+
|
| 41 |
+
| | |
|
| 42 |
+
| --- | --- |
|
| 43 |
+
| Pretrained backbone | `vit_base_patch16_224` |
|
| 44 |
+
| Image size | 224 |
|
| 45 |
+
| Frames per clip | 12 |
|
| 46 |
+
| Frame stride | 2 |
|
| 47 |
+
| Epochs | 5 |
|
| 48 |
+
| Batch size | 2 (gradient accumulation = 16) |
|
| 49 |
+
| Optimizer | AdamW |
|
| 50 |
+
| Backbone LR | 5e-5 |
|
| 51 |
+
| Head LR | 2.5e-4 |
|
| 52 |
+
| Weight decay | 0.05 |
|
| 53 |
+
| Mixed precision | Yes (`torch.amp`) |
|
| 54 |
+
|
| 55 |
+
## Result
|
| 56 |
+
|
| 57 |
+
Top-1 validation accuracy on the held-out HMDB51 split: **~32.7%** (best
|
| 58 |
+
checkpoint). This is a short 5-epoch run on a small batch size and should be
|
| 59 |
+
treated as a starting point rather than a competitive HMDB51 number.
|
| 60 |
+
|
| 61 |
+
## Usage
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
import torch
|
| 65 |
+
from modeling import ViTConfig, LSViTForAction, HMDB51_CLASSES
|
| 66 |
+
|
| 67 |
+
config = ViTConfig(image_size=224)
|
| 68 |
+
model = LSViTForAction(config, num_classes=51)
|
| 69 |
+
|
| 70 |
+
ckpt = torch.load("lsvit_hmdb51_best.pt", map_location="cpu", weights_only=False)
|
| 71 |
+
model.load_state_dict(ckpt["model"])
|
| 72 |
+
model.eval()
|
| 73 |
+
|
| 74 |
+
# video: (B, T, C, H, W) — float tensor in [0, 1] normalized with
|
| 75 |
+
# mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225). Trained with T=12.
|
| 76 |
+
video = torch.randn(1, 12, 3, 224, 224)
|
| 77 |
+
with torch.no_grad():
|
| 78 |
+
logits = model(video)
|
| 79 |
+
|
| 80 |
+
pred = logits.argmax(dim=-1).item()
|
| 81 |
+
print(HMDB51_CLASSES[pred])
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
### Downloading from the Hub
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
from huggingface_hub import hf_hub_download
|
| 88 |
+
|
| 89 |
+
weights_path = hf_hub_download("devicoal/lsvit_hmdb51", "lsvit_hmdb51_best.pt")
|
| 90 |
+
modeling_path = hf_hub_download("devicoal/lsvit_hmdb51", "modeling.py")
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
## Classes
|
| 94 |
+
|
| 95 |
+
51 HMDB51 action categories (alphabetical, matching `sorted(os.listdir(...))`):
|
| 96 |
+
|
| 97 |
+
```
|
| 98 |
+
brush_hair, cartwheel, catch, chew, clap, climb, climb_stairs, dive,
|
| 99 |
+
draw_sword, dribble, drink, eat, fall_floor, fencing, flic_flac, golf,
|
| 100 |
+
handstand, hit, hug, jump, kick, kick_ball, kiss, laugh, pick, pour, pullup,
|
| 101 |
+
punch, push, pushup, ride_bike, ride_horse, run, shake_hands, shoot_ball,
|
| 102 |
+
shoot_bow, shoot_gun, sit, situp, smile, smoke, somersault, stand,
|
| 103 |
+
swing_baseball, sword, sword_exercise, talk, throw, turn, walk, wave
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
## License
|
| 107 |
+
|
| 108 |
+
Apache-2.0.
|