This repo is forked from https://github.com/deepinsight/insightface. I use their face detection (retinaface) and face recognition (arcface).
I used to use their gender and age estimation as well, but the accuracy is very bad so I had to drop it.
I have a new age-gender estimation model. Check out the repo and the demo video.
I made a light-weight flask server that loads the modules and waits for the client calls.
You can either run the app.py
directly in Python3 or in a docker container.
Pulling and running the docker containers is easier and recommended.
-
Pull and run on CPU
-
Pull the image from docker hub and run the container.
docker run -it --rm -p 10002:10002 tae898/face-detection-recognition
-
Build it (optional)
If you want to build this container from scratch for whatever reason, you can do so.
Make sure your current directory is the root directory of this repo.
First download the models and unzip them.
wget https://github.com/tae898/face-detection-recognition/releases/download/models/models.zip unzip models.zip
And build it.
docker build -t face-detection-recognition .
-
-
Pull and run on GPU
-
Pull the image from docker hub and run the container.
docker run -it --rm -p 10002:10002 --gpus all tae898/face-detection-recognition-cuda
-
Build it (optional)
If you want to build this container from scratch for whatever reason, you can do so.
Make sure your current directory is the root directory of this repo.
First download the models and unzip them.
wget https://github.com/tae898/face-detection-recognition/releases/download/models/models.zip unzip models.zip
And build it.
docker build -f Dockerfile-cuda -t face-detection-recognition-cuda .
-
First your current directory should be the root directory of this repo.
-
Download the models and unzip them.
wget https://github.com/tae898/face-detection-recognition/releases/download/models/models.zip unzip models.zip mkdir -p ~/.insightface/ mv models ~/.insightface/
-
Install the requirements.
pip3 install -r requirements.txt
-
Install the insightface python package.
cd python-package && pip install . && cd ..
-
Run both apps.
python3 app.py --gpu-id -1
You should send an image as json. I know this is not conventional but somehow this works really good. Below is an example code.
import jsonpickle
import requests
import pickle
with open('/path/to/image', 'rb') as stream:
frame_bytestring = stream.read()
data = {'image': frame_bytestring}
data = jsonpickle.encode(data)
response = requests.post('http://127.0.0.1:10002/', json=data)
response = jsonpickle.decode(response.text)
face_detection_recognition = response['face_detection_recognition']
with open('/path/to/save/results', 'wb') as stream:
pickle.dump(face_detection_recognition, stream)
face_detection_recognition
is a list of dict
s. The number of dict
s correspond to the number of faces detected in the image. Every dict
has four key-value pairs. They are:
bbox: bounding box (four floating point numbers).
det_score: detection confidence score (one floating point)
landmark: five facial landmarks (5 by 2 float array)
normed_embedding: face embedding (512-dimensional floating point vector)
The best way to find and solve your problems is to see in the github issue tab. If you can't find what you want, feel free to raise an issue. We are pretty responsive.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request