Skip to content

bdbotond/dual_face_age_pred

Repository files navigation

Models are available for testing at https://photoage.sztaki.hu

Improving face age prediction by using multiple angles photos

Our goal was to predict the age from different angels photos, and check if the predictions can be improved if we use two images at the same time.

Dataset description

For training and testing we used the Kaggle IDOC dataset, which uses mugshots from Illionis Department Of Corrections, and tabular data with rich annotations from Illionis Prison Population Data Sets. The full dataset contains more than 50000 individual. The youngest age was 17 years and the oldest age was 83 years.

Training the models

We split the data into training, validation, and testing sets by using 0.6, 0.2, and 0.2 ratio respectively, and the removing those pictures when multiple pictures are taken of one person. After this the train set contains 32577 images, the validation set contains 9685 images, the test set contains 9189 images. All of the images have been cropped using Retinaface face detector followed by padding to a square and resized to 224x244 pixels. Then we trained a Res-Net 50 model on the training dataset by modifying the final layer to a single-layer neuron. We trained separate models using only front face photos (Front model), only side view face photos (Side model), and both front and side view face photos pictures (Front + Side model).

Models

We have three models, one using frontal images, side images, and the third using both images.

Model name Model file
Front front_model.pt
Side side_model.pt
Front_Side dual_model.pt

To use the models make sure you intall the packages from requiments.txt, and put the files in the directory strucure shown below:

├── base_folder/
│   ├── predict_one_image.py
│   ├── predict_from_csv.py
│   ├── models/
│   │   ├── front_model.pt
│   │   ├── side_model.pt
│   │   ├── dual_model.pt 
│ 

Predict one image

To predict one image use predict_one_image.py, it will print out the predicted age.:

python3 predict_one_image.py direction image_path
  • Replace <direction> with the desired model type: front,side, or dual

  • Replace <image_path> with the path of your image file.

Predict images from .csv file

To predict batches of images you can use predict_from_csv.py , put the path of the images into the path column:

python3 predict_image_csv.py direction csv_file
  • Replace <direction> with the desired model type: front,side, or dual

  • Replace <csv_file> with the path of your '.csv' file.

  • Add front image paths <front_path> column in the '.csv' file.

  • Add side image paths <side_path> column in the '.csv' file.

  • The predictions will be saved into <csv_file>_predict.csv:

To plot GRAD-CAM heatpams

Command Line Arguments

  1. GPU ID: The index of the GPU to be used. Example: --gpu 0 WARNING: high gpu usage
  2. Dataset Path: The file path to the CSV dataset. Example: --dataset_path /path/to/dataset.csv
  3. Direction: The direction for inference ('front', 'side', or 'two'). Example: --direction front
python gradcam_test.py --gpu 0 --dataset_path /path/to/dataset.csv --direction front
  • Then in plot the results in gradcam_results_plot.ipynb

Reproduce the results

  • If you have boundig boxes to the dataset, or your faces has boundung boxes, use the <train_model_cropped_face.py>. You can train it from a '.csv' file, with image paths in the column path and ages in the column age, and bounding box points in x1,x2,x3,x4 columns.
  • To train the model run the following code, with first arument is the <gpu_id> and second is the <data_file_path.csv> file:
python3 train_model_cropped_face.py  gpu_id data_file_path.csv
  • If you dont hage bounding box for the faces you can use Retinaface, to crop the images (means extra GPU usage), for this you can use <train_model.py>. You can train it from a '.csv' file, with image paths in the column path and ages in the column age.
    • To train the model run the following code, with first arument is the <gpu_id> and second is the <data_file_path.csv> file:
python3 train_model.py  gpu_id data_file_path.csv

Authors

  • Botond Bárdos Deák ,Bence Király ,Csaba Kerepesi

Contact

For questions or feedback, please contact Botond Bárdos Deák at bdbotond@sztaki.hu

About

Improving face age prediction by using multiple angles photos

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors