bozliu / CelebA-Challenge

40 face attributes prediction on CelebA benchmark with PyTorch Implementation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AI6126 Project 1: CelebA Facial Attribute Recognition Challenge

40 face attributes prediction on CelebA benchmark with PyTorch Implementation.
The challange is to deal with domain gap and imbalanced data of the dataset.
Three effective ways are summarized in my blog article.

Baseline

Face attribute prediction

Dependencies

  • Anaconda3 (Python 3.7.6, with Numpy etc.)
  • PyTorch 1.6
  • tensorboard, tensorboardX

Dataset

  • CelebA dataset is a large-scale face dataset with attribute-based annotations. Cropped and aligned face regions are utilized as the training source.
  • Pre-processed data and specific split list has been uploaded to list directory.
  • lfwA+ dataset is the private test dataset.

Data Pre-processing

After downloading the dataset, please unzip img_align_celeba. Put the folder of Anno with two files, list_eval_partition.txt and list_attr_celeba.txt inside. The folder of img_align_celeba and Anno are in the same directory with Data Pre-processing.py

Dataset Structure

├── Anno
├── identity_CelebA.txt
├── list_attr_celeba.txt
├── list_bbox_celeba.txt
├── list_eval_partition.txt
├── list_landmarks_align_celeba.txt
└── list_landmarks_celeba.txt

├── Eval
└── list_eval_partition.txt

├── img_align_celeba [Face Pictures]
├── test_attr_list.txt
├── train_attr_list.txt
└── val_attr_list.txt

Checkpoints

  1. checkpoints_CrossEntropyLoss20 : Training with Cross Entropy loss for 20 epochs
  2. checkpoints_FocalLoss20: Training with focal loss for 20 epochs
  3. checkpoints+CrossEntropy20+FocalLoss7: Training with Cross Entropy loss for 20 epochs and continue to train with focal loss for another 7 epochs

Run Scripts

Train

! python main.py -d './img_align_celeba' --resume './face-attribute-prediction/checkpoints/checkpoint.pth.tar' --gpu-id '0,1'

-d refers to the location of image dataset, img_align_celeba
--resume refers to the location of checkpoints
--gpu-id refers to the GPU number on the cluster

Validation

! python main.py -d './img_align_celeba' -e --gpu-id '0,1'
-e refers to the validation mode

Test

! python main.py -d './img_align_celeba' -t --gpu-id '0,1'
-t refers to the test mode

Results

  • Table1. Average accuracy with the combined loss function, cross-entropy loss for 20 epochs and focal loss for 7 epochs
Validation Accuracy Test Accuracy
Average Accuracy 91.3018 90.9309
  • Table 2 Average accuracy for single loss function
Single Loss Function Maximum Training epochs Validation Accuracy Test Accuracy
Cross-Entropy 20 90.7780 90.5587
Focal Loss 20 91.1635 90.7420
  • Table 3. Accuracy for each attribute with the combined two loss function (cross-entropy loss for 20 epochs and focal loss for 7 epochs)
Attributes Validation Accuracy Test Accuracy
5 o’clock Shadow 93.8139 94.2240
Arched Eyebrows 83.9936 82.7322
Attractive 80.5356 82.1210
Bags Under Eyes 83.9332 84.3753
Bald 98.7920 98.8077
Bangs 95.6460 95.5265
Big Lips 82.4986 71.5109
Big Nose 82.4936 83.6389
Black Hair 91.3928 89.7305
Blond Hair 95.3591 95.8271
Blurry 96.3105 96.0876
Brown Hair 85.7603 89.2997
Bushy Eyebrows 92.1679 92.3404
Chubby 95.1981 95.3411
Double Chin 96.2652 96.1427
Eyeglasses 99.3507 99.4590
Goatee 96.2853 97.3299
Gray Hair 97.7551 98.0212
Heavy Makeup 91.8206 91.1332
High cheekbones 87.7133 86.8751
Male 98.1376 97.8609
Mouth Slightly Open 93.4867 93.1770
Mustache 96.1595 96.7588
Narrow Eyes 92.6612 87.0905
No Beard 95.6863 95.6217
Oval Face 75.3914 74.9775
Pale Skin 96.8943 97.1245
Pointy Nose 76.4031 76.4703
Receding Hairline 94.3474 93.3774
Rosy Cheeks 95.0018 95.1007
Sideburns 96.9094 97.6155
Smiling 92.4800 92.2553
Straight Hair 82.8963 82.7071
Wavy Hair 84.5321 83.0578
Wearing Earrings 90.4817 89.5301
Wearing Hat 98.7869 98.9831
Wearing Lipstick 92.2384 93.6279
Wearing Necklace 88.6646 86.7398
Wearing Necktie 96.2249 96.7188
Young 87.6026 87.9170

Detail File Structure

├── celeba.py
├── checkpoints
├── checkpoint.pth.tar
├── log.eps
├── logs
├── log.txt
├── model_best.pth.tar
├── checkpoints_CrossEntropyLoss20
├── checkpoints_FocalLoss20
├── focal_loss.py
├── LICENSE
├── main.py
├── models
├── init.py
├── mobilenetv1.py
├── mobilenetv2.py
└── resnet.py
├── Model Structure
├── Model Summary
├── prediction.txt
├── README.md
└── utils

  • celeba.py performs a map-style dataset representing a map from indices/keys to data samples used as one of inputs for DataLoader.
  • checkpoints is to save the checkpoint of model in each epoch and also to save the model with highest validation accuracy so far. The loss function of the saved model checkpoints folder are two combined loss function with cross-entropy loss for the first 20 epochs and focal loss for the next 7 epochs
  • checkpoints_CrossEntropyLoss20 is to save the checkpoint of model with highest validation accuracy during the training with single loss function, cross-entropy loss for 20 epochs.
  • checkpoints_FocalLoss20 is to save the checkpoint of model with highest validation accuracy during the training with single loss function, focal loss for 20 epochs.
  • focal_loss.py implements the focal loss function.
  • main.py is the main function of the project
  • models is the folder with different model structure. resnet.py is the one used in this project.
  • Model Structure print the model, ResNet-50 used in this project
  • Model Summary prints all layers in ResNet-50, the output shape and parameters of each layers, and the total parameters used for an single image input.
  • prediction.txt is predictions of the given new test set
  • utils are the utility function required by the project

About

40 face attributes prediction on CelebA benchmark with PyTorch Implementation.

License:MIT License


Languages

Language:Python 100.0%