This repository contains code to instantiate and deploy a facial age estimation model. The model detects faces in an image, extracts facial features for each face detected and finally predicts the age of each face. The model uses a coarse-to-fine strategy to perform multi-class classification and regression for age estimation. The input to the model is an image and the output is a list of estimated ages and bounding box coordinates of each face detected in the image. The format of the bounding box coordinates is [xmin, ymin, width, height]
.
The model is based on the SSR-Net model. The model files are hosted on IBM Cloud Object Storage. The code in this repository deploys the model as a web service in a Docker container. This repository was developed as part of the IBM Code Model Asset Exchange.
Domain | Application | Industry | Framework | Training Data | Input Data Format |
---|---|---|---|---|---|
Vision | Facial Recognition | General | Keras & TensorFlow | IMDB-WIKI Dataset | Image (PNG/JPG) |
- T.-Y. Yang, Y.-H. Huang, Y.-Y. Lin, P.-C. Hsiu, and Y.-Y. Chuang. "SSR-Net: A Compact Soft Stagewise Regression Network for Age Estimation", IJCAI, 2018.
- SSR-Net Github Repository
Component | License | Link |
---|---|---|
This repository | Apache 2.0 | LICENSE |
Model Weights | MIT | LICENSE |
Model Code (3rd party) | MIT | LICENSE |
Test assets | Various | Asset README |
docker
: The Docker command-line interface. Follow the installation instructions for your system.- The minimum recommended resources for this model is 2GB Memory and 1 CPU.
To run the docker image, which automatically starts the model serving API, run:
$ docker run -it -p 5000:5000 codait/max-facial-age-estimator
This will pull a pre-built image from Docker Hub (or use an existing image if already cached locally) and run it. If you'd rather checkout and build the model locally you can follow the run locally steps below.
You can also deploy the model on Kubernetes using the latest docker image on Docker Hub.
On your Kubernetes cluster, run the following commands:
$ kubectl apply -f https://github.com/IBM/MAX-Facial-Age-Estimator/raw/master/max-facial-age-estimator.yaml
The model will be available internally at port 5000
, but can also be accessed externally through the NodePort
.
Clone this repository locally. In a terminal, run the following command:
$ git clone https://github.com/IBM/MAX-Facial-Age-Estimator.git
Change directory into the repository base folder:
$ cd MAX-Facial-Age-Estimator
To build the docker image locally, run:
$ docker build -t max-facial-age-estimator .
Note that currently this docker image is CPU only (we will add support for GPU images later).
To run the docker image, which automatically starts the model serving API, run:
$ docker run -it -p 5000:5000 max-facial-age-estimator
The API server automatically generates an interactive Swagger documentation page. Go to http://localhost:5000
to load it. From there you can explore the API and also create test requests.
Use the model/predict
endpoint to load a test image (you can use one of the test images from the assets
folder) and get predictions for the image from the API.
You can also test it on the command line, for example:
$ curl -F "image=@assets/tom_cruise.jpg" -XPOST http://localhost:5000/model/predict
You should see a JSON response like that below:
{
"status": "ok",
"predictions": [
{
"age_estimation": 48,
"face_box": [
303,
174,
379,
515
]
}
]
}
To run the Flask API app in debug mode, edit config.py
to set DEBUG = True
under the application settings. You will then need to rebuild the docker image (see step 1).
To stop the Docker container, type CTRL
+ C
in your terminal.