Ad Corre
aliprfIntroduction
Ad-Corre introduces an Adaptive Correlation-Based Loss designed to enhance Facial Expression Recognition (FER) in challenging environments. This approach leverages Deep Metric Learning (DML) to improve the discriminative power of embedded features by focusing on intra-class variations and inter-class similarities. The Ad-Corre method comprises three components: Feature Discriminator, Mean Discriminator, and Embedding Discriminator, each contributing to the generation of highly correlated feature vectors for similar classes and less correlated ones for different classes. The model uses the Xception network as its backbone and achieves notable accuracy on datasets like AffectNet, RAF-DB, and FER-2013.
Architecture
The Ad-Corre model architecture consists of three main components:
- Feature Discriminator: Ensures embedded feature vectors are highly correlated within the same class.
- Mean Discriminator: Encourages distinct mean features for different classes.
- Embedding Discriminator: Penalizes the generation of dissimilar embedded feature vectors.
This structure is built on the Xception network, with an embedding feature space containing multiple feature vectors. The network is trained using Ad-Corre Loss combined with cross-entropy loss.
Training
The Ad-Corre model can be trained from scratch using the train.py
script. The training process involves:
- Selecting the dataset (e.g., AffectNet) and dataset type (
train_7
). - Configuring the architecture (
xcp
for Xception) and specifying weight paths.
Data preparation requires normalization and saving in .npy
format.
Guide: Running Locally
-
Install Requirements: Ensure Python 3.5 or higher is installed. Use the command:
pip install -r requirements.txt
-
Use Pre-trained Models: Available in the
Trained_Models
directory. Predict facial emotions with:tester = TestModels(h5_address='./trained_models/AffectNet_6336.h5') tester.recognize_fer(img_path='./img.jpg')
-
Training from Scratch: Refer to
train.py
and execute the training script:trainer = TrainModel(dataset_name=DatasetName.affectnet, ds_type=DatasetType.train_7) trainer.train(arch="xcp", weight_path="./")
For intensive computations, consider using cloud GPUs from providers like AWS or Google Cloud.
License
The Ad-Corre model is licensed under the MIT License.