Skip to content
PatrickStarLPublic

About

Semi-supervised facial expression recognition via semantic-, instance-, and text-level pseudo-label fusion. PyTorch implementation with RAF-DB support.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SIT-FER: Integration of Semantic-, Instance-, Text-level Information for Semi-supervised Facial Expression Recognition

Python 3.7+ PyTorch License: MIT

πŸ“‹ Overview

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

Architecture

✨ Key Features

  • 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

πŸ—οΈ Project Structure

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 β€” see legacy/README.md for a file-by-file mapping to its replacement and a known caveat about pretrained-weight differences.

πŸš€ Getting Started

Installation

  1. Clone the repository
git clone https://github.com/PatrickStarL/SIT-FER.git
cd SIT-FER
  1. Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Install the package in development mode
pip install -e .

Requirements

  • Python 3.7+
  • PyTorch 1.13.0+
  • CUDA (for GPU training)
  • See requirements.txt for full dependencies

Dataset Preparation

Download the datasets from:

Organize the dataset as follows:

RAFdataset/
β”œβ”€β”€ images/
β”‚   β”œβ”€β”€ train/
β”‚   └── test/
└── labels/
    β”œβ”€β”€ RAF_train_label2.txt
    └── RAF_test_label2.txt

Pretrained Backbone (optional but recommended)

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

If left as null, the backbone falls back to ImageNet-pretrained torchvision weights instead. See legacy/README.md for details on the expected checkpoint format.

πŸ‹οΈ Training

Basic Training

python scripts/train.py --config configs/base.yaml --gpu 0

Configuration

Modify 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.5

πŸ“Š Evaluation

python scripts/test.py --checkpoint experiments/<exp_name>/best_model.pth --config configs/base.yaml

πŸ“¦ Pretrained Models

Download pretrained models from:

πŸ§ͺ Key Improvements (This Refactored Version)

This refactored implementation includes significant engineering improvements over the original:

Code Organization

  • βœ… Modular architecture with clear separation of concerns
  • βœ… Package structure with proper __init__.py files
  • βœ… Type hints for better code clarity
  • βœ… Consistent naming conventions

Configuration Management

  • βœ… YAML-based configuration system
  • βœ… Easy hyperparameter tuning
  • βœ… Config versioning for reproducibility

Training Infrastructure

  • βœ… TensorBoard logging
  • βœ… Checkpoint management (save/load)
  • βœ… Progress bars with tqdm
  • βœ… Comprehensive logging system
  • βœ… Random seed management for reproducibility

Code Quality

  • βœ… Proper error handling
  • βœ… Documentation strings
  • βœ… Setup.py for pip installation
  • βœ… Requirements management
  • βœ… .gitignore for clean repository

Best Practices

  • βœ… Device-agnostic code (CPU/GPU)
  • βœ… Memory-efficient data loading
  • βœ… Gradient accumulation support (ready to add)
  • βœ… Mixed precision training (ready to add)

πŸ“ˆ Performance

Our method achieves state-of-the-art performance on RAF-DB and other FER datasets. See the paper for detailed results.

πŸ”§ Development

Running Tests

pytest tests/

Code Style

# Format code
black src/

# Check style
flake8 src/

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“š Citation

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}
}

πŸ™ Acknowledgments

  • Original research by PatrickStarL
  • RAF-DB dataset creators
  • PyTorch team for the excellent framework

πŸ“§ Contact

For questions or issues, please:

πŸ—ΊοΈ Roadmap

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

About

Semi-supervised facial expression recognition via semantic-, instance-, and text-level pseudo-label fusion. PyTorch implementation with RAF-DB support.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages