Skip to main content

InsightFace Toolkit

Project description

License

The code of InsightFace Python Library is released under the MIT License. There is no limitation for both academic and commercial usage.

The pretrained models we provided with this library are available for non-commercial research purposes only, including both auto-downloading models and manual-downloading models.

Install

pip install -U insightface

Quick Example

import cv2
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image

app = FaceAnalysis()
app.prepare(ctx_id=0, det_size=(640, 640))
img = ins_get_image('t1')
faces = app.get(img)
rimg = app.draw_on(img, faces)
cv2.imwrite("./t1_output.jpg", rimg)

This quick example will detect faces from the t1.jpg image and draw detection results on it.

Inference Backend

For insightface<=0.1.5, we use MXNet as inference backend.

(You may please download all models from onedrive, and put them all under ~/.insightface/models/ directory to use this old version)

Starting from insightface>=0.2, we use onnxruntime as inference backend.

(You have to install onnxruntime-gpu to enable GPU inference)

Model Zoo

In the latest version of insightface library, we provide following model packs:

Name

Detection Model

Recognition Model

Alignment

Attributes

antelopev2

SCRFD-10GF

ResNet100@Glint360K

2d106 & 3d68

Gender&Age

Note that these models are available for non-commercial research purposes only.

For insightface>=0.3.3, models will be downloaded automatically once we init app = FaceAnalysis() instance.

For insightface==0.3.2, you must first download the model package by command:

insightface-cli model.download antelope

or

insightface-cli model.download antelopev2

Use Your Own Licensed Model

You can simply create a new model directory under ~/.insightface/models/ and replace the pretrained models we provide with your own models. And then call app = FaceAnalysis(name='your_model_zoo') to load these models.

Call Models

The latest insightface libary only supports onnx models. Once you have trained detection or recognition models by PyTorch, MXNet or any other frameworks, you can convert it to the onnx format and then they can be called with insightface library.

Call Detection Models

import cv2
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image

# Method-1, use FaceAnalysis
app = FaceAnalysis(allowed_modules=['detection']) # enable detection model only
app.prepare(ctx_id=0, det_size=(640, 640))

# Method-2, load model directly
detector = insightface.model_zoo.get_model('your_detection_model.onnx')
detector.prepare(ctx_id=0, det_size=(640, 640))

Call Recognition Models

import cv2
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image

handler = insightface.model_zoo.get_model('your_recognition_model.onnx')
handler.prepare(ctx_id=0)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

insightface-0.3.6.tar.gz (386.4 kB view details)

Uploaded Source

File details

Details for the file insightface-0.3.6.tar.gz.

File metadata

  • Download URL: insightface-0.3.6.tar.gz
  • Upload date:
  • Size: 386.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

File hashes

Hashes for insightface-0.3.6.tar.gz
Algorithm Hash digest
SHA256 935749ef610dbd9d74e7f315575aa31ac8a112c0add98a3e87b5a62f993bc663
MD5 b29ea73fad8eeab22e43928b2111b88c
BLAKE2b-256 f9c1398e0b84a6335d35358d330fa17a3b4c53b7ef7fcbff5ef39b15b43809a7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page