ArcFace : A Machine Learning Model for Face Recognition.

David Cochard
axinc-ai
Published in
3 min readMay 21, 2021

This is an introduction to「ArcFace」, a machine learning model that can be used with ailia SDK. You can easily use this model to create AI applications using ailia SDK as well as many other ready-to-use ailia MODELS.

Overview

ArcFace is a machine learning model that takes two face images as input and outputs the distance between them to see how likely they are to be the same person. It can be used for face recognition and face search.

ArcFace uses a similarity learning mechanism that allows distance metric learning to be solved in the classification task by introducing Angular Margin Loss to replace Softmax Loss.

The distance between faces is calculated using cosine distance, which is a method used by search engines and can be calculated by the inner product of two normalized vectors. If the two vectors are the same, θ will be 0 and cosθ=1. If they are orthogonal, θ will be π/2 and cosθ=0. Therefore, it can be used as a similarity measure.

(Source:https://arxiv.org/abs/1801.07698

In a typical classification task, after calculating features, the Fully Connected (FC) layer takes the inner product of features and weights and applies Softmax to the output.

In ArcFace, cosθ is calculated by normalizing features and FC layer weights and taking the inner product. The loss is calculated by applying Softmax to cosθ. At this point, we apply arccos to the cosθ values after taking the inner product, and add an angular margin of +m only for the correct labels. In this way, we prevent the weight of the FC layer from being overly dependent on the input data set.

ArcFace inference process

During inference, the features of the two faces are normalized and the inner-product is computed to determine if both pictures are the same person.

After the input face image is converted to grayscale, it is input as is in batch 1, and the same image horizontally flipped as in put in batch 2, and features are concatenated.

ArcFace accuracy

ArcFace performed best on the LFW Dataset.

(Source:https://arxiv.org/abs/1801.07698
(Source:https://arxiv.org/abs/1801.07698

We can see that the accuracy changes depending on the margins that is used. We can also see that introducing a margin into CosFace improves the accuracy.

Usage

The following sample demonstrates how to use ArcFace with ailia SDK.

When inputing two face images, it will determine if they are the same person or not.

$ python3 arcface.py — inputs IMAGE_PATH1 IMAGE_PATH2

When a video is input, YOLOv3Face is used to cut out the face and ArcFace is used to determine if it is the same person and assign an ID to the face.

$ python3 arcface.py -v 0

ax Inc. has developed ailia SDK, which enables cross-platform, GPU-based rapid inference.

ax Inc. provides a wide range of services from consulting and model creation, to the development of AI-based applications and SDKs. Feel free to contact us for any inquiry.

--

--