Giter Club home page Giter Club logo

face-detection-recognition's Introduction

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

face-detection-recognition's People

Contributors

nttstar avatar anxiangsir avatar jiankangdeng avatar guoxiawang avatar wenmuzhou avatar tae898 avatar qingpingzheng avatar yuzhenbo avatar barisgecer avatar xiaoyang-coder avatar littletomatodonkey avatar maldil avatar olojuwin avatar leondgarse avatar 007gzs avatar chenjoya avatar deftruth avatar szad670401 avatar shiquanyu avatar krenax avatar sthphoenix avatar shinkansan avatar tengerye avatar nihui avatar ppwwyyxx avatar yingfeng avatar sagarbhathwar avatar nlqq avatar itsnine avatar guanlaoda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.