This repository contains a simple webservice offering an HTTP API to perform Facial Expression Recognition (FER).
POST a single image containing a human face and get a response with probabilities for seven basic emotions:
curl -X 'POST' \
'http://localhost:8000/recognize/file' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@fer/test/test_image.png'
{
"anger": 0.051,
"disgust": 0.049,
"fear": 0.1,
"happiness": 0.7,
"neutral": 0.099,
"sadness": 0.001,
"surprise": 0.0
}
If you have Docker installed just build the image:
docker build -t fer-ms .
and run a container:
docker run -p 8000:8000 fer-ms
You may change the first 8000
to map the service to the desired port on your machine.
You may find a complete exemplary machine/environment definition in this repository's Dockerfile.
If you just want to run the application, install all application requirements by running:
pip install -r requirements.txt
and then run the application via:
uvicorn fer.main:app --host 0.0.0.0 --port 8000
If you also want to run the tests, install all requirements by running:
pip install -r requirements-dev.txt
and then, to run the test:
python -m pytest fer/test
You can find the API definition in main.py.
To GET a ping:
curl -X 'GET' \
'http://localhost:8000/ping' \
-H 'accept: application/json'
To POST an image file:
curl -X 'POST' \
'http://localhost:8000/recognize/file' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@fer/test/test_image.png'
To POST a base64 encoded image:
curl -X 'POST' \
'http://localhost:8000/recognize/base64' \
-H 'accept: application/json' \
-H 'Content-Type: text/plain' \
-d '@fer/test/test_image_base64.txt'
With the virtual environment activated, execute:
python demo.py
Look around the fer/test folder for examples in Python code.