SIT-FER: Integration of Semantic-, Instance-, Text-level Information for Semi-supervised Facial Expression Recognition
This is a refactored and production-ready implementation of SIT-FER, a semi-supervised deep facial expression recognition framework. The method addresses the challenge of limited labeled data by integrating three levels of information to generate high-quality pseudo-labels:
- Semantic-level: Traditional classification probabilities
- Instance-level: Similarities between facial features and instance representations
- Text-level: Similarities between facial vision features and textual emotion descriptions
- Three-level Information Fusion: Combines semantic, instance, and text-level information for robust pseudo-labeling
- Text-supervised Learning: Leverages emotion descriptions to enhance visual feature learning
- State-of-the-art Performance: Outperforms current SS-DFER methods and even exceeds some fully supervised baselines
SIT-FER/
βββ configs/ # Configuration files
β βββ base.yaml # Base configuration
βββ src/
β βββ sit_fer/ # Main package
β βββ core/ # Core components (config, trainer)
β βββ models/ # Model definitions
β βββ losses/ # Loss functions
β βββ data/ # Dataset loaders
β βββ utils/ # Utility functions
βββ scripts/ # Training/testing scripts
β βββ train.py # Main training script
βββ docs/ # Documentation (refactoring notes, before/after comparison)
βββ tests/ # Unit tests
βββ experiments/ # Experiment logs and checkpoints (git-ignored)
βββ legacy/ # Original pre-refactor code, kept for reference only
βββ requirements.txt # Python dependencies
βββ setup.py # Package setup
βββ README.md # This file
Note:
legacy/holds the original, unrefactored implementation. Nothing in the active codebase imports from it β seelegacy/README.mdfor a file-by-file mapping to its replacement and a known caveat about pretrained-weight differences.
- Clone the repository
git clone https://github.com/PatrickStarL/SIT-FER.git
cd SIT-FER- Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Install the package in development mode
pip install -e .- Python 3.7+
- PyTorch 1.13.0+
- CUDA (for GPU training)
- See requirements.txt for full dependencies
Download the datasets from:
Organize the dataset as follows:
RAFdataset/
βββ images/
β βββ train/
β βββ test/
βββ labels/
βββ RAF_train_label2.txt
βββ RAF_test_label2.txt
The original SIT-FER paper initializes the ResNet-18 backbone from a face-recognition-pretrained checkpoint (ResNet-18 pretrained on MS-Celeb-1M), not plain ImageNet weights. This checkpoint is not distributed with this repo β you need to source it yourself. Once you have it, point the config at it:
model:
pretrained_path: /path/to/resnet18_msceleb.pthIf left as null, the backbone falls back to ImageNet-pretrained torchvision weights instead. See legacy/README.md for details on the expected checkpoint format.
python scripts/train.py --config configs/base.yaml --gpu 0Modify configs/base.yaml to customize:
- Model architecture
- Training hyperparameters
- Data augmentation
- Loss weights
- And more...
Example configuration snippet:
training:
epochs: 80
batch_size: 16
lr: 0.0001
loss_weights:
supervised: 0.4
text: 0.4
consistency: 0.2
pseudo_label:
threshold: 0.75
fusion_weights:
semantic: 0.3
text: 0.2
instance: 0.5python scripts/test.py --checkpoint experiments/<exp_name>/best_model.pth --config configs/base.yamlDownload pretrained models from:
This refactored implementation includes significant engineering improvements over the original:
- β Modular architecture with clear separation of concerns
- β
Package structure with proper
__init__.pyfiles - β Type hints for better code clarity
- β Consistent naming conventions
- β YAML-based configuration system
- β Easy hyperparameter tuning
- β Config versioning for reproducibility
- β TensorBoard logging
- β Checkpoint management (save/load)
- β Progress bars with tqdm
- β Comprehensive logging system
- β Random seed management for reproducibility
- β Proper error handling
- β Documentation strings
- β Setup.py for pip installation
- β Requirements management
- β .gitignore for clean repository
- β Device-agnostic code (CPU/GPU)
- β Memory-efficient data loading
- β Gradient accumulation support (ready to add)
- β Mixed precision training (ready to add)
Our method achieves state-of-the-art performance on RAF-DB and other FER datasets. See the paper for detailed results.
pytest tests/# Format code
black src/
# Check style
flake8 src/This project is licensed under the MIT License - see the LICENSE file for details.
If you use this code in your research, please cite:
@article{sitfer2024,
title={Integration of Semantic-, Instance-, Text-level Information for Semi-supervised Facial Expression Recognition},
author={Your Name},
journal={arXiv preprint},
year={2024}
}- Original research by PatrickStarL
- RAF-DB dataset creators
- PyTorch team for the excellent framework
For questions or issues, please:
- Open an issue on GitHub
- Contact: [[email protected]]
- Add support for more datasets (FERPlus, AffectNet)
- Implement data augmentation strategies (RandAugment, etc.)
- Add mixed precision training
- Create Docker container for easy deployment
- Add Gradio demo for interactive testing
- Comprehensive unit tests
- API documentation with Sphinx
Note: This is a refactored and improved version of the original SIT-FER project, with better code organization, documentation, and engineering practices.
