Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Micro-Expression Spotting and Recognition
|
| 2 |
+
|
| 3 |
+
**[δΈζζζ‘£](README_zh.md)** | English
|
| 4 |
+
|
| 5 |
+
A PyTorch-based end-to-end framework for **micro-expression recognition** (short clips) and **long-video micro-expression spotting**, with a built-in web visualization platform.
|
| 6 |
+
|
| 7 |
+
Supports datasets: CASME2 / SAMM / SMIC-HS / CAS(ME)Β³
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## Quick Start
|
| 12 |
+
|
| 13 |
+
### 1. Set up environment
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
conda create -n me-env python=3.10
|
| 17 |
+
conda activate me-env
|
| 18 |
+
|
| 19 |
+
# GPU (CUDA 12.1)
|
| 20 |
+
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
|
| 21 |
+
|
| 22 |
+
# CPU only
|
| 23 |
+
# conda install pytorch torchvision torchaudio cpuonly -c pytorch
|
| 24 |
+
|
| 25 |
+
pip install -r requirements.txt
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
### 2. Download model weights
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
from huggingface_hub import snapshot_download
|
| 32 |
+
|
| 33 |
+
snapshot_download(
|
| 34 |
+
repo_id="ghy-cmd/micro-expression-weights",
|
| 35 |
+
local_dir=".", # restores checkpoints/ and weights/ under project root
|
| 36 |
+
)
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### 3. Start the web app
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
python -m webapp.app
|
| 43 |
+
# open http://localhost:5001
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## Features
|
| 49 |
+
|
| 50 |
+
| Feature | Description |
|
| 51 |
+
|---------|-------------|
|
| 52 |
+
| **Micro-Expression Recognition** | Upload a short video clip, auto-preprocess and classify emotion via PGCAN model |
|
| 53 |
+
| **Long-Video Spotting** | Upload any long video, auto face-crop + sliding-window inference, locates all micro-expression intervals |
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## Model Description
|
| 58 |
+
|
| 59 |
+
### Task 1 Β· Micro-Expression Recognition
|
| 60 |
+
|
| 61 |
+
Classifies short clips into **3 categories**: Positive / Negative / Surprise
|
| 62 |
+
|
| 63 |
+
- HRNet feature extractor on onset & apex frames β (2, 256, 64, 64)
|
| 64 |
+
- TV-L1 optical flow (u, v, strain) β (3, 256, 256)
|
| 65 |
+
- Transformer encoder with attention fusion (16 heads, 4 stages, full guidance)
|
| 66 |
+
- Trained with LOSO cross-validation on Composite dataset (CASME2 + SMIC-HS + SAMM)
|
| 67 |
+
|
| 68 |
+
### Task 2 Β· Long-Video Micro-Expression Spotting
|
| 69 |
+
|
| 70 |
+
Detects all micro-expression intervals in arbitrary-length videos, classifies each into **4 categories**: Positive / Negative / Surprise / Others
|
| 71 |
+
|
| 72 |
+
- Sliding-window inference (window = 0.4s, stride = 0.2s @ 30 fps)
|
| 73 |
+
- Multi-scale temporal features (6 scales)
|
| 74 |
+
- Dual-task head: detection score + emotion classification
|
| 75 |
+
- Trained on CAS(ME)Β³-LV dataset
|
| 76 |
+
- Evaluation metric: overlap-based F1 (any frame overlap = TP)
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## Preprocessing Pipeline
|
| 81 |
+
|
| 82 |
+
Both tasks share the same pipeline, consistent with dataset preprocessing:
|
| 83 |
+
|
| 84 |
+
1. **Face crop** (dlib 68-point landmarks) β 256Γ256
|
| 85 |
+
2. **Apex frame detection** (optical strain + UPC) β recognition only
|
| 86 |
+
3. **HRNet feature extraction** β (2, 256, 64, 64)
|
| 87 |
+
4. **Optical flow** (TV-L1) β (3, 256, 256)
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
## Training
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
# Recognition β LOSO training
|
| 95 |
+
python train_loso.py --config configs/train_loso.yaml --dataset composite
|
| 96 |
+
|
| 97 |
+
# Detection β LOSO training
|
| 98 |
+
python detection/train_detection.py --config configs/detection_config.yaml
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
See [docs/TRAINING_GUIDE.md](docs/TRAINING_GUIDE.md) for full training guide.
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## Project Structure
|
| 106 |
+
|
| 107 |
+
```
|
| 108 |
+
βββ webapp/ # Web visualization platform (Flask)
|
| 109 |
+
β βββ app.py # Entry point β http://localhost:5000
|
| 110 |
+
β βββ api/ # REST API (recognition + detection)
|
| 111 |
+
β βββ core/ # Inference wrappers
|
| 112 |
+
βββ models/ # Model architectures
|
| 113 |
+
βββ detection/ # Spotting training & evaluation
|
| 114 |
+
βββ trainers/ # Recognition training utilities
|
| 115 |
+
βββ configs/ # YAML config files
|
| 116 |
+
βββ datasets/ # Dataset loaders
|
| 117 |
+
βββ utils/ # Shared utilities
|
| 118 |
+
βββ docs/ # Documentation & visualization scripts
|
| 119 |
+
βββ train_loso.py # Recognition LOSO training script
|
| 120 |
+
βββ requirements.txt
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
+
## License
|
| 126 |
+
|
| 127 |
+
[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) β free for academic & personal use, **commercial use prohibited**.
|