Coder Social home page Coder Social logo

igorhoholko / faces_detanator Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 0.0 14.65 MB

High accurate tool for automatic faces detection with landmarks

License: The Unlicense

Dockerfile 0.08% Python 95.88% Shell 0.08% Cython 0.05% C++ 1.75% Cuda 2.16%
deep-learning computer-vision faces detection faces-detection landmark-detection keypoint-detection python ai artificial-intelligence

faces_detanator's Introduction

faces_detanator

Python

High accurate tool for automatic faces detection with landmarks.

The library is based on public detectors with high accuracy (TinaFace, Retinaface, SCRFD, ...) which are combined together to form an ansamle. All models predict detections, then voting algorithm performs aggregation.

screen shot 2017-08-07 at 12 18 15 pm screen shot 2017-08-07 at 12 18 15 pm screen shot 2017-08-07 at 12 18 15 pm

🛠️Prerequisites

  1. Install Docker
  2. Install Nvidia Docker Container Runtime
  3. Install nvidia-container-runtime: apt-get install nvidia-container-runtime
  4. Set "default-runtime" : "nvidia" in /etc/docker/daemon.json:
    {
        "default-runtime": "nvidia",
        "runtimes": {
            "nvidia": {
                "path": "nvidia-container-runtime",
                "runtimeArgs": []
            }
        }
    }
  5. Restart Docker: systemctl restart docker
  6. Install git-lfs to pull artifacts: git lfs install

🚀  Quickstart

docker can require sudo permission and it is used in run.py script. So in this case run run.py script with sudo permission or add your user to docker group.

# clone project
https://github.com/IgorHoholko/faces_detanator

# [OPTIONAL] create virtual enviroment
virtualenv venv --python=python3.7
source venv/bin/activate

# install requirements
pip install -r requirements.txt

💥 Annotate your images

To start annotating, run the command:

python run.py -i <path_to_your_images>

For more information run:

python run.py -h

😱 More functions?

You can visualize your results:

python -m helpers.draw_output -i <your_meta> -h

You can filter your metadata by threshold after it is formed. Just run:

python -m helpers.filter_output_by_conf -i <your_meta> -t <thres> -h

👀 Adding new detectors for ansamble

To add new detector to ansamble you need to perform the next steps:

Take a look at existing detectors to make process easier.

  1. Create a folder for your detector <detector> in detectors/ folder.
  2. Prepare inference script for your detector. First, define "-i", "--input" argparse parameter which is responsible for input. The script to process the input:
if args.input.split('.')[-1] in ('jpg', 'png'):
    img_paths = [args.input]
else:
    img_paths = glob.glob(f"{args.input}/**/*.jpg", recursive=True)
    img_paths.extend(  glob.glob(f"{args.input}/**/*.png", recursive=True) )
  1. Next create "-o", "--output" argparse parameter. The place where annotation will be saved
  2. Now you need to save your annotations in required format. The script to save annotations looks like this:
data = []
for ipath, (bboxes, kpss) in output.items():
    line = [ipath, str(len(bboxes)), '$d']
    for i in range(len(bboxes)):
        conf = bboxes[i][-1]
        bbox = bboxes[i][:-1]
        bbox = list(map(int, bbox))
        bbox = list(map(str, bbox))

        landmarks = np.array(kpss[i]).astype(int).flatten()
        landmarks = list(map(str, landmarks))
        line.append(str(conf))
        line.extend(bbox)
        line.extend(landmarks)

    data.append(' '.join(line))

with open(os.path.join(args.output, 'meta.txt'), 'w') as f:
    f.write('\n'.join(data))

If your detector doesn't provide landmarks - set landmarks to be array with all -1

  1. When inference script is ready, create entrypoint.sh in the root of <detector> folder. entrypoint.sh describes the logic how to infer your detector. It can look like this:
#!/bin/bash
source venv/bin/activate
python3 tools/scrfd.py -s outputs/ "$@"

IMPORTANT set -s here to outputs.

  1. Now create Dockerfile for your detector with defined earlier entrypoint.
  2. Add your detector to settings.yaml by the sample.
  3. Done!

faces_detanator's People

Contributors

igorhoholko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.