tae898 / face-detection-recognition

This repo is forked from https://github.com/deepinsight/insightface. I use their face detection (retinaface) and face recognition (arcface).
MIT License
10 stars 10 forks source link
docker flask mxnet python

Face detection and recognition

DOI

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.

Flask server.

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.

Run in a docker container (recommended)

Run directly (CPU only)

First your current directory should be the root directory of this repo.

  1. 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/
  2. Install the requirements.

    pip3 install -r requirements.txt
  3. Install the insightface python package.

    cd python-package && pip install . && cd ..
  4. Run both apps.

    python3 app.py --gpu-id -1

Making a REST POST request to the flask server.

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 dicts. The number of dicts 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)

Troubleshooting

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.

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Authors