infer_uniface_verification

infer_uniface_verification

About

1.0.0
MIT

Face verification using UniFace - verify if two faces belong to the same person

uniface
face
verification
recognition
arcface
identity

Run face verification to compare two face images and determine if they belong to the same person using UniFace library. UniFace is a lightweight production-ready face analysis library built on ONNX Runtime, combining face detection and recognition models (ArcFace/AdaFace).

🚀 Use with Ikomia API

1. Install Ikomia API

We strongly recommend using a virtual environment. If you're not sure where to start, we offer a tutorial here.

pip install ikomia

2. Create your workflow

from ikomia.dataprocess.workflow import Workflow

# Init your workflow
wf = Workflow()

# Set input images
wf.set_image_input(url="https://raw.githubusercontent.com/yakhyo/uniface/refs/heads/main/assets/test_images/image0.jpg", index=0)
wf.set_image_input(url="https://raw.githubusercontent.com/yakhyo/uniface/refs/heads/main/assets/test_images/image1.jpg", index=1)

# Add face verification algorithm
verifier = wf.add_task(name="infer_uniface_verification", auto_connect=True)

# Run the workflow
wf.run()

# Get results
display(verifier.get_input(0).get_image())
display(verifier.get_input(1).get_image())
dict_output = verifier.get_output(1)
result_data = dict_output.data
print(f"Similarity score: {result_data.get('similarity_score')}")
print(f"Same person: {result_data.get('same_person')}")

☀️ Use with Ikomia Studio

Ikomia Studio offers a friendly UI with the same features as the API.

  • If you haven't started using Ikomia Studio yet, download and install it from this page.
  • For additional guidance on getting started with Ikomia Studio, check out this blog post.

📝 Set algorithm parameters

from ikomia.dataprocess.workflow import Workflow

# Init your workflow
wf = Workflow()

# Set input images
wf.set_image_input(url="https://raw.githubusercontent.com/yakhyo/uniface/refs/heads/main/assets/test_images/image0.jpg", index=0)
wf.set_image_input(url="https://raw.githubusercontent.com/yakhyo/uniface/refs/heads/main/assets/test_images/image1.jpg", index=1)

# Add face verification algorithm
verifier = wf.add_task(name="infer_uniface_verification", auto_connect=True)

verifier.set_parameters({
"detector_name": "retinaface",
"conf_thres": "0.5",
"nms_thres": "0.4",
"recognizer_name": "arcface",
"similarity_threshold": "0.6"
})

# Run the workflow
wf.run()

# Get results
display(verifier.get_input(0).get_image())
display(verifier.get_input(1).get_image())
dict_output = verifier.get_output(1)
result_data = dict_output.data
print(f"Similarity score: {result_data.get('similarity_score')}")
print(f"Same person: {result_data.get('same_person')}")

Parameters

  • detector_name (str, default="retinaface"): Face detection model to use. Options: "retinaface", "yolov5face", "scrfd", "yolov8face".
  • conf_thres (float, default="0.5"): Object detection confidence threshold.
  • nms_thres (float, default="0.4"): Non-maximum suppression threshold.
  • recognizer_name (str, default="arcface"): Face recognition model to use. Options: "arcface", "adaface", "mobileface", "sphereface".
  • similarity_threshold (float, default="0.6"): Threshold for determining if two faces belong to the same person. Similarity scores above this threshold indicate the same person.

Note: parameter key and value should be in string format when added to the dictionary.

🔍 Explore algorithm outputs

Every algorithm produces specific outputs, yet they can be explored them the same way using the Ikomia API. For a more in-depth understanding of managing algorithm outputs, please refer to the documentation.

from ikomia.dataprocess.workflow import Workflow

# Init your workflow
wf = Workflow()

# Set input images
wf.set_image_input(url="https://raw.githubusercontent.com/yakhyo/uniface/refs/heads/main/assets/test_images/image0.jpg", index=0)
wf.set_image_input(url="https://raw.githubusercontent.com/yakhyo/uniface/refs/heads/main/assets/test_images/image1.jpg", index=1)

# Add face verification algorithm
verifier = wf.add_task(name="infer_uniface_verification", auto_connect=True)

# Run the workflow
wf.run()
# Iterate over outputs
for output in verifier.get_outputs():
# Print information
print(output)
# Export it to JSON
output.to_json()

💻 How it works

The algorithm works in these steps:

  1. Face Detection: Detects faces in both input images using the selected detector model (RetinaFace, YOLOv5Face, SCRFD, or YOLOv8Face).
  2. Face Embedding: Extracts face embeddings (feature vectors) from the detected faces using the selected recognizer model (ArcFace or AdaFace).
  3. Similarity Computation: Computes cosine similarity between the two face embeddings.
  4. Verification: Compares the similarity score with the threshold to determine if the faces belong to the same person.

The similarity score ranges from -1 to 1, where higher values indicate greater similarity. A threshold of 0.6 is commonly used (scores above = same person, below = different people). You can adjust this threshold based on your use case.

Developer

  • Ikomia
    Ikomia

License

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

PermissionsConditionsLimitations

Commercial use

License and copyright notice

Liability

Modification

Warranty

Distribution

Private use

This is not legal advice: this description is for informational purposes only and does not constitute the license itself. Provided by choosealicense.com.