Skip to main content

InspireFace Python API

InspireFace provides an easy-to-use Python API that wraps the underlying dynamic link library through ctypes. You can install the latest release version via pip or configure it using the project's self-compiled dynamic library.

Quick Installation

pip install inspireface

Python 3.7 automatically selects modelscope<1.22.1, and Python 3.8 selects modelscope<1.29.2. Those newer ModelScope releases require Python 3.8 syntax and Python 3.9's zoneinfo, respectively, without declaring the minimum in their package metadata. Python 3.9 and newer keep the normal ModelScope dependency selection. These compatibility constraints apply on all supported operating systems.

Manual Installation

  1. Copy the compiled dynamic library to the specified directory:
# Copy the compiled dynamic library to the corresponding system architecture directory
cp YOUR_BUILD_DIR/libInspireFace.so inspireface/modules/core/SYSTEM/CORE_ARCH/
  1. Install the Python package and its declared dependencies:
pip install .

Quick Start

Here's a simple example showing how to use InspireFace for face detection and landmark drawing:

import cv2
import inspireface as isf

isf.launch()
try:
    with isf.InspireFaceSession(
        param=isf.HF_ENABLE_NONE,
        detect_mode=isf.HF_DETECT_MODE_ALWAYS_DETECT,
        auto_launch=False,
    ) as session:
        session.set_detection_confidence_threshold(0.5)

        image = cv2.imread("path/to/your/image.jpg")
        if image is None:
            raise FileNotFoundError("Unable to read the input image")

        faces = session.face_detection(image)
        print(f"Detected {len(faces)} faces")

        draw = image.copy()
        for face in faces:
            x1, y1, x2, y2 = face.location
            center = ((x1 + x2) / 2, (y1 + y2) / 2)
            size = (x2 - x1, y2 - y1)
            rect = (center, size, face.roll)
            box = cv2.boxPoints(rect).astype(int)
            cv2.drawContours(draw, [box], 0, (100, 180, 29), 2)

            landmarks = session.get_face_dense_landmark(face)
            for x, y in landmarks.astype(int):
                cv2.circle(draw, (x, y), 0, (220, 100, 0), 2)
finally:
    if isf.query_launch_status():
        isf.terminate()

More Examples

The project provides multiple example files demonstrating different features:

  • sample_face_detection.py: Basic face detection
  • sample_face_track_from_video.py: Video face tracking
  • sample_face_recognition.py: Face recognition
  • sample_face_comparison.py: Face comparison
  • sample_feature_hub.py: Feature extraction
  • sample_system_resource_statistics.py: System resource statistics

Running Tests

The comprehensive Python suite shares the same test_res fixture tree as the C++ API tests:

python -m sample_testcase.run --native-lib ../build/lib/libInspireFace.so

Notes

  1. Ensure that OpenCV and other necessary dependencies are installed on your system
  2. Make sure the dynamic library is correctly installed before use
  3. Python 3.7 or higher is recommended
  4. The default version is CPU, if you want to use the GPU, CoreML, or NPU backend version, you can refer to the documentation to replace the so and make a Python installation package

Metadata

Release files for inspireface 1.2.4.post3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for inspireface 1.2.4.post3
File
inspireface-1.2.4.post3-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
inspireface-1.2.4.post3-py3-none-manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
inspireface-1.2.4.post3-py3-none-manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
inspireface-1.2.4.post3-py3-none-macosx_12_0_x86_64.whl Python 3 none macOS 12.0+ x86-64 Details
inspireface-1.2.4.post3-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 13.7 MB

Release files / inspireface-1.2.4.post3-py3-none-win_amd64.whl

Download URL inspireface-1.2.4.post3-py3-none-win_amd64.whl
Size 2.3 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
c88b3464737005c4b4bde70e7dfdb68ca250d1777f6fe7dde4ab8179e8df6595
BLAKE2b-256 checksum
How to use checksums
4d7723085149989718e4dc1c3b338e5f6a6e8b459b6a642effb141d12da156e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / inspireface-1.2.4.post3-py3-none-manylinux2014_x86_64.whl

Download URL inspireface-1.2.4.post3-py3-none-manylinux2014_x86_64.whl
Size 3.3 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
198547a6e5b647396fabd5389acc0498c33ee4e3aa412199224bd685c0f4cd79
BLAKE2b-256 checksum
How to use checksums
2c9d6f5d36812db4ed85b974053f3110eb3eb920a528b0d95d946647fee4f24a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / inspireface-1.2.4.post3-py3-none-manylinux2014_aarch64.whl

Download URL inspireface-1.2.4.post3-py3-none-manylinux2014_aarch64.whl
Size 3.1 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
86343a0b51fd62958a0b6f30e8ac568924bda9bdee7ea93520758d4530d814be
BLAKE2b-256 checksum
How to use checksums
58c29f4b5bf98ca743f520c1f620c269ed82a3db85d56c3db541ec86d4d9240c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / inspireface-1.2.4.post3-py3-none-macosx_12_0_x86_64.whl

Download URL inspireface-1.2.4.post3-py3-none-macosx_12_0_x86_64.whl
Size 2.7 MB
Tags Python 3 macOS 12.0+ x86-64
SHA-256 checksum
How to use checksums
3e28d2c4345d884ef3c2e74ff293f5c239c1a1d80b0b3495dcf599d4a0111272
BLAKE2b-256 checksum
How to use checksums
bc89e7cb0a0754eca23a9e9fc4e2b6fa05e6c9dfcce2482a516b37a451b4fb24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / inspireface-1.2.4.post3-py3-none-macosx_11_0_arm64.whl

Download URL inspireface-1.2.4.post3-py3-none-macosx_11_0_arm64.whl
Size 2.3 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
edff1f5b7a86ccdc77566d341070b2597b0375140c49df7f73595394da36691b
BLAKE2b-256 checksum
How to use checksums
68f491db3de3d26759666b2dc90503539f1884f5c96951e0adceb9457c4bddb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page