Models are available for testing at https://photoage.sztaki.hu
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.
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.
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).
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
│ 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.
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:
- GPU ID: The index of the GPU to be used. Example:
--gpu 0WARNING: high gpu usage - Dataset Path: The file path to the CSV dataset. Example:
--dataset_path /path/to/dataset.csv - 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
- 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 columnpathand ages in the columnage, and bounding box points inx1,x2,x3,x4columns. - 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 columnpathand ages in the columnage. -
- To train the model run the following code, with first arument is the
<gpu_id>and second is the<data_file_path.csv>file:
- To train the model run the following code, with first arument is the
python3 train_model.py gpu_id data_file_path.csv
- Botond Bárdos Deák ,Bence Király ,Csaba Kerepesi
For questions or feedback, please contact Botond Bárdos Deák at bdbotond@sztaki.hu