ghy-cmd's picture
Upload README.md with huggingface_hub
141d3d6 verified
|
Raw
History Blame Contribute Delete
4.07 kB
---
license: cc-by-nc-4.0
language:
- en
- zh
tags:
- micro-expression
- facial-expression-recognition
- video-classification
- spotting
- pytorch
pipeline_tag: video-classification
---
# Micro-Expression Spotting and Recognition
**[δΈ­ζ–‡ζ–‡ζ‘£](README_zh.md)** | English
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.
Supports datasets: CASME2 / SAMM / SMIC-HS / CAS(ME)Β³
---
## Quick Start
### 1. Set up environment
```bash
conda create -n me-env python=3.10
conda activate me-env
# GPU (CUDA 12.1)
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
# CPU only
# conda install pytorch torchvision torchaudio cpuonly -c pytorch
pip install -r requirements.txt
```
### 2. Download model weights
```python
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="ghy-cmd/micro-expression-weights",
local_dir=".", # restores checkpoints/ and weights/ under project root
)
```
### 3. Start the web app
```bash
python -m webapp.app
# open http://localhost:5001
```
---
## Features
| Feature | Description |
|---------|-------------|
| **Micro-Expression Recognition** | Upload a short video clip, auto-preprocess and classify emotion via PGCAN model |
| **Long-Video Spotting** | Upload any long video, auto face-crop + sliding-window inference, locates all micro-expression intervals |
---
## Model Description
### Task 1 Β· Micro-Expression Recognition
Classifies short clips into **3 categories**: Positive / Negative / Surprise
- HRNet feature extractor on onset & apex frames β†’ (2, 256, 64, 64)
- TV-L1 optical flow (u, v, strain) β†’ (3, 256, 256)
- Transformer encoder with attention fusion (16 heads, 4 stages, full guidance)
- Trained with LOSO cross-validation on Composite dataset (CASME2 + SMIC-HS + SAMM)
### Task 2 Β· Long-Video Micro-Expression Spotting
Detects all micro-expression intervals in arbitrary-length videos, classifies each into **4 categories**: Positive / Negative / Surprise / Others
- Sliding-window inference (window = 0.4s, stride = 0.2s @ 30 fps)
- Multi-scale temporal features (6 scales)
- Dual-task head: detection score + emotion classification
- Trained on CAS(ME)Β³-LV dataset
- Evaluation metric: overlap-based F1 (any frame overlap = TP)
---
## Preprocessing Pipeline
Both tasks share the same pipeline, consistent with dataset preprocessing:
1. **Face crop** (dlib 68-point landmarks) β†’ 256Γ—256
2. **Apex frame detection** (optical strain + UPC) β€” recognition only
3. **HRNet feature extraction** β†’ (2, 256, 64, 64)
4. **Optical flow** (TV-L1) β†’ (3, 256, 256)
---
## Training
```bash
# Recognition β€” LOSO training
python train_loso.py --config configs/train_loso.yaml --dataset composite
# Detection β€” LOSO training
python detection/train_detection.py --config configs/detection_config.yaml
```
See [docs/TRAINING_GUIDE.md](docs/TRAINING_GUIDE.md) for full training guide.
---
## Project Structure
```
β”œβ”€β”€ webapp/ # Web visualization platform (Flask)
β”‚ β”œβ”€β”€ app.py # Entry point β†’ http://localhost:5000
β”‚ β”œβ”€β”€ api/ # REST API (recognition + detection)
β”‚ └── core/ # Inference wrappers
β”œβ”€β”€ models/ # Model architectures
β”œβ”€β”€ detection/ # Spotting training & evaluation
β”œβ”€β”€ trainers/ # Recognition training utilities
β”œβ”€β”€ configs/ # YAML config files
β”œβ”€β”€ datasets/ # Dataset loaders
β”œβ”€β”€ utils/ # Shared utilities
β”œβ”€β”€ docs/ # Documentation & visualization scripts
β”œβ”€β”€ train_loso.py # Recognition LOSO training script
└── requirements.txt
```
---
## License
[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) β€” free for academic & personal use, **commercial use prohibited**.