Face recognition program

In this tutorial, we'll show you how easy is identifying people on image or video with the Abraia Python SDK. Just follow these simple steps:

Step 1: Install the Abraia Python SDK

You can install the package on Windows, Mac, and Linux:

python -m pip install -U abraia

Step 2: Load and run the face recognition model

Import the FaceRecognizer class from abraia inference. Then use "load_image" and run the model to detect every face in the image. Build the index with a portrait image of every person you want to identify in the image. Finally, identify people on the image using the previously generated search index, and use "render_results" to show the results on the image.

import os

from abraia.inference import FaceRecognizer
from abraia.utils import load_image, save_image, render_results

img = load_image('images/rolling-stones.jpg')
out = img.copy()

recognition = FaceRecognizer()
results = recognition.represent_faces(img)

index = []
for src in ['mick-jagger.jpg', 'keith-richards.jpg', 'ronnie-wood.jpg', 'charlie-watts.jpg']:
    img = load_image(f"images/{src}")
    rslt = recognition.represent_faces(img)[0]
    index.append({'name': os.path.splitext(src)[0], 'embeddings': rslt['embeddings']})

results = recognition.identify_faces(results, index)
render_results(out, results)
save_image(out, 'images/rolling-stones-identified.jpg')
rolling stones members identified

Step 3: Run the face recognition model on video

Import the class "Video" to create a video object to iterate on the frames. Input the path for a video file or "Video(0)" to use your webcam. So, you can directly run the model directly on your camera stream, and show the results using the "show" method from video.

from abraia.utils import Video

video = Video(0)
for frame in video:
    results = recognition.represent_faces(frame)
    results = recognition.identify_faces(results, index)
    frame = render_results(frame, results)
    video.show(frame)

Congratulations! You have successfully run the face recognition model on a video. This tutorial provides a basic overview, and you can further explore advanced features, optimize your model, and fine-tune parameters based on your specific use case. Refer to DeepLab's contact email for more detailed information and features.