This project is intended to showcase the usage of a Keras multi-output model to predict age, gender and ethnicity from a given persons face. The generated model is served through a REST API provided by Flask running on Python 3.6.
Running the project
A live demo of application is available on the https://face2data.herokuapp.com/ address (it may take some time to load due to Heroku's free plan), but if you instead would like to run it locally, below are the needed steps:
In order to run this project locally, you first need to clone this repository into our machine and then install the required dependencies. The project dependencies are located in the requirements.txt file. You can install them by using PiP, as below:
pip install -r requirements.txt
After this, navigate to the project root directory and run the following command on the terminal to start the application:
This should start a new server on the port 5000. You can then access the applicaton by opening the address http://localhost:5000/ on the browser.
The UTKFace dataset is a large dataset composed of over 20 thousand face images with their respective annotations of age, gender and ethnicity. The images are properly cropped into the face region, but display some variations in pose, illumination, resolution, etc. If you want to know more about this dataset, please check their website.
Our Neural Network is composed of three major branches, one for each of the features we are trying to predict. We have used a default set of hidden layers, based on the stacking of several Conv2D with ReLU activation, followed by a Batch Normalization, then a MaxPooling and finally a Dropout layer.
We performed our training phase by adopting an Adam optimizer with a learning rate of 1e-4 and a decay based on the initial learning rate divided by the number of epochs. A hundred epochs were used to train our model, in which we have seen that we had an efficient learning process, asserted by plotting both the accuracy and loss curves, as shown below:
Accuracy for gender feature
Accuracy for race feature
Mean Absolute Error for age feature
- Add unit tests for both Flask application and model predictions
- Setup Continuous Integration and Deployment to automatically deploy on Heroku upon a new commit
- Add SHAP model explanations
Subscribe to Python Awesome
Get the latest posts delivered right to your inbox