Skip to main content

InsightFace Python Library

Project description

InsightFace Python Library

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

Install Inference Backend


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

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

You have to install ``onnxruntime-gpu`` manually to enable GPU
inference, or install ``onnxruntime`` to use CPU only inference.

Change Log
----------

[0.6] - 2022-01-29
~~~~~~~~~~~~~~~~~~

Added
^^^^^

-  Add pose estimation in face-analysis app.

Changed
^^^^^^^

-  Change model automated downloading url, to ucloud.

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(providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
    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.

Model Zoo
---------

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

Name in **bold** is the default model pack. **Auto** means we can
download the model pack through the python library directly.

+--------+---------+-----------+-------+------+------+-----------------------------+--------+
| Name   | Detecti | Recogniti | Align | Attr | Mode | Link                        | Auto   |
|        | on      | on        | ment  | ibut | l-Si |                             |        |
|        | Model   | Model     |       | es   | ze   |                             |        |
+========+=========+===========+=======+======+======+=============================+========+
| antelo | SCRFD-1 | ResNet100 | 2d106 | Gend | 407M | `link <https://drive.google | N      |
| pev2   | 0GF     | @Glint360 | &     | er&A | B    | .com/file/d/18wEUfMNohBJ4K3 |        |
|        |         | K         | 3d68  | ge   |      | Ly5wpTejPfDzp-8fI8/view?usp |        |
|        |         |           |       |      |      | =sharing>`__                |        |
+--------+---------+-----------+-------+------+------+-----------------------------+--------+
| **buff | SCRFD-1 | ResNet50@ | 2d106 | Gend | 326M | `link <https://drive.google | Y      |
| alo\_l | 0GF     | WebFace60 | &     | er&A | B    | .com/file/d/1qXsQJ8ZT42_xSm |        |
| **     |         | 0K        | 3d68  | ge   |      | WIYy85IcidpiZudOCB/view?usp |        |
|        |         |           |       |      |      | =sharing>`__                |        |
+--------+---------+-----------+-------+------+------+-----------------------------+--------+
| buffal | SCRFD-2 | ResNet50@ | 2d106 | Gend | 313M | `link <https://drive.google | N      |
| o\_m   | .5GF    | WebFace60 | &     | er&A | B    | .com/file/d/1net68yNxF33NNV |        |
|        |         | 0K        | 3d68  | ge   |      | 6WP7k56FS6V53tq-64/view?usp |        |
|        |         |           |       |      |      | =sharing>`__                |        |
+--------+---------+-----------+-------+------+------+-----------------------------+--------+
| buffal | SCRFD-5 | MBF@WebFa | 2d106 | Gend | 159M | `link <https://drive.google | N      |
| o\_s   | 00MF    | ce600K    | &     | er&A | B    | .com/file/d/1pKIusApEfoHKDj |        |
|        |         |           | 3d68  | ge   |      | eBTXYB3yOQ0EtTonNE/view?usp |        |
|        |         |           |       |      |      | =sharing>`__                |        |
+--------+---------+-----------+-------+------+------+-----------------------------+--------+
| buffal | SCRFD-5 | MBF@WebFa | -     | -    | 16MB | `link <https://drive.google | Y      |
| o\_sc  | 00MF    | ce600K    |       |      |      | .com/file/d/19I-MZdctYKmVf3 |        |
|        |         |           |       |      |      | nu5Da3HS6KH5LBfdzG/view?usp |        |
|        |         |           |       |      |      | =sharing>`__                |        |
+--------+---------+-----------+-------+------+------+-----------------------------+--------+

Recognition Accuracy:

+----------+-------+--------+----------+-----------+----------+------+-------+---------+----------+
| Name     | MR-AL | Africa | Caucasia | South     | East     | LFW  | CFP-F | AgeDB-3 | IJB-C(E4 |
|          | L     | n      | n        | Asian     | Asian    |      | P     | 0       | )        |
+==========+=======+========+==========+===========+==========+======+=======+=========+==========+
| buffalo\ | 91.25 | 90.29  | 94.70    | 93.16     | 74.96    | 99.8 | 99.33 | 98.23   | 97.25    |
| _l       |       |        |          |           |          | 3    |       |         |          |
+----------+-------+--------+----------+-----------+----------+------+-------+---------+----------+
| buffalo\ | 71.87 | 69.45  | 80.45    | 73.39     | 51.03    | 99.7 | 98.00 | 96.58   | 95.02    |
| _s       |       |        |          |           |          | 0    |       |         |          |
+----------+-------+--------+----------+-----------+----------+------+-------+---------+----------+

*buffalo\_m has the same accuracy with buffalo\_l.*

*buffalo\_sc has the same accuracy with buffalo\_s.*

**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, input_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.7.tar.gz (437.1 kB view hashes)

Uploaded Source

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