| --- |
| 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**. |
|
|