Skip to content

This repo is forked from https://github.com/deepinsight/insightface. I use their face detection (retinaface) and face recognition (arcface).

License

Notifications You must be signed in to change notification settings

xl8-ai/face-detection-recognition

 
 

Repository files navigation

Face detection and recognition

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)

  • Pull and run on CPU

    1. Pull the image from docker hub and run the container.

      docker run -it --rm -p 10002:10002 tae898/face-detection-recognition
    2. 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

    1. Pull the image from docker hub and run the container.

      docker run -it --rm -p 10002:10002 --gpus all tae898/face-detection-recognition-cuda
    2. 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 .  

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.

Cite our work

DOI

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

About

This repo is forked from https://github.com/deepinsight/insightface. I use their face detection (retinaface) and face recognition (arcface).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 86.0%
  • Jupyter Notebook 12.1%
  • Cython 0.8%
  • C 0.5%
  • Cuda 0.2%
  • C++ 0.2%
  • Other 0.2%