This CLI program is an implementation of the FairFace DeepLearning model that provides sensitive annotation - race, gender and age - based on images.
If one is in need of evaluating fairness over a ML model based on images of people, one might need to use an annotated dataset. In order to generate fast labeled data from unlabeled images, this application is very handy.
If one is in need of assess the level of diversity of an unlabeled image dataset.
- Image Fairness Regressor
- The pre-trained model is available in the README File from https://github.com/dchen236/FairFace.
- Appliation File:
scripts/fairness_detection_cli.py
The CLI application uses an --input
CSV file containing the the full path to all images to be processed under the column name of "img_path"
to load each image and run the FairFace Model over it. All outputs are saved at the end under another CSV file specified in the --output
parameter.
- Loading input image;
- Detect the face using the Face Detector;
- Generate face landmarks using the Shape Predictor Landmark;
- Crop image using a padding over the predicted landmarks;
- Fairness Regressor;
--input
,-i
:- CSV file containing the path to all images within the column name
"img_path"
.
- CSV file containing the path to all images within the column name
--output
,-o
:- Valid path to the output CSV file containing the model's results.
--fairness-model
,-f
:- Path to the fairness model weights.
- Default:
'assets/res34_fair_align_multi_7_20190809.pt'
--number-races
,-n
:- Number of race features outputed by the model. Should be 4 or 7.
- Default=
7
IMPORTANT: Use the same number of race classes from the loaded model version in the
--fairness-model
Parameter.--device
:- Process device: CPU or GPU. Should be cpu or gpu.
- Default:
'cpu'
--not-clip-face
:- Flag to prevent face clipping prior to fairness detection.
Tip: Recommended if already using cropped faces.
--padding
:- Padding used for the clipping phase.
- Default:
0.25
Warning: If using --not-clip-face argument, it is not used.
--size
:- Size resize clipped image.
- Default:
300
Warning: If using --not-clip-face argument, it is not used.
--face-detector-model
:- Path to the Face detector model weights.
- Default:
'assets/dlib_models/mmod_human_face_detector.dat'
Warning: If using --not-clip-face argument, it is not used.
--shape-predictor-model
:- Path to shape predictor landmark model weights.
- Default:
'assets/dlib_models/shape_predictor_5_face_landmarks.dat'
Warning: If using --not-clip-face argument, it is not used.
--save-clip-image
:- Directory to save clipped the images.
If using --not-clip-face argument, it is not used.
$ python scripts/fairness_detection_cli.py --input ./input.csv --output output.csv -n 7 --device cpu --padding 0.30 --save-clip-image ./clipped-output-folder/ -f ./models/res34_fair_align_multi_7_20190809.pt
All requirements are in the requirements.txt
file. From pip, just run in the terminal the following command and you are ready to go.
$ pip install -r requirements.txt
The shellscript files under the project root were made to simplify the process of using the project with Docker, therefore one only need to follow the steps below:
Simply run the docker_build.sh
script. It will automatically map your username, user id and group id to the image.
$ ./docker_build.sh
Within the docker_run.sh
script are all the parameters and volumes needed in order to run the application from a docker container. Just need to follow the pointers below:
$ ./docker_run.sh
1. Make sure to mount all volumes needed correctly.
If the images needed are in the /home/user/dataset
directory, the container can only access it if the volume is mounted.
2. All paths from the input CSV file must follows the CONTAINER. If the script is running inside a container, it needs to find the images within it. Make sure to map correctly the path all images are going to be.
Python
OpenCV
Docker
Dlib
PyTorch
All logs can be accessed from the ./etc/logs/app.log
file within the project root.
FairFace: Face Attribute Dataset for Balanced Race, Gender, and Age
Github: https://github.com/dchen236/FairFace
Karkkainen, K., & Joo, J. (2021). FairFace: Face Attribute Dataset for Balanced Race, Gender, and Age for Bias Measurement and Mitigation. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (pp. 1548-1558).
@inproceedings{karkkainenfairface,
title={FairFace: Face Attribute Dataset for Balanced Race, Gender, and Age for Bias Measurement and Mitigation},
author={Karkkainen, Kimmo and Joo, Jungseock},
booktitle={Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision},
year={2021},
pages={1548--1558}
}