Implement ArcFace Loss for MNIST Classification – Things You Must Know – PyTorch Tutorial

By | May 19, 2022

ArcFace loss is widely used in face recognition and image classification. In this tutorial, we will introduce some important things you must notice when using it.

We will use it for MNIST classification.

ArcFace loss

It is defined as:

ArcFace loss function

In order to use this loss, we should determine the value of s and m.

How to determine s and m?

From some experiments we can find:

The value of s and m should determined by image feature dimension.

For example, if the image feature is 1*512, which means the image feature dimension is 512.

s and m can be 64 and 0.5

It means s = 64 and m = 0.5

However, if the image feature is 1*512, we need use t-SNE to convert it to 2D point.

from sklearn.manifold import TSNE
tsne_2D = TSNE(n_components=2, init='pca', random_state=0)
result_2D = tsne_2D.fit_transform(x)

We will see an image as follows:

ArcFace loss wit t-SNE for MNIST classification

If you want to see arcface loss effect as follows:

ArcFace loss effect on MNIST classification

We need make the feature is 2D dimension (1*2). At this situation, s and m can be 10.0 and 0.2

It means s = 10.0 and m = 0.2

If you still use 64 and 0.5, we will get worse effect when the feature is 2D dimension.

Leave a Reply