This repository contains the project where I contributed to the TensorFlow Team during GSoC in the year 2022.
- Special thanks to Yusuf Sarıgoz @monatis for being perfect mentor.
Additive Angular Margin Loss (ArcFace) has a clear geometric interpretation due to the exact correspondence to the geodesic distance on the hypersphere, and consistently outperforms the state-of-the-art and can be easily implemented with negligible computational overhead.
import tensorflow as tf
import tensorflow_similarity as tfsim
labels = tf.Variable([1, 0])
embeddings = tf.Variable([[0.2, 0.3, 0.1], [0.4, 0.5, 0.5]])
#create loss according to your data
loss_fn = tfsim.losses.ArcFaceLoss(num_classes=2, embedding_size=3)
loss = loss_fn(labels, embeddings)
import tensorflow as tf
import tensorflow_similarity as tfsim
#extract the required variable
num_classes = np.unique(y_train).size
embedding_size = model.get_layer('metric_embedding').output.shape[1]
#create loss according to your data
loss = tfsim.losses.ArcFaceLoss(num_classes= num_classes, embedding_size=embedding_size, name="ArcFaceLoss")
#compile your model with your loss
model.compile(optimizer=tf.keras.optimizers.SGD(LR), loss=loss, distance=distance)
ArcFace: Additive Angular Margin Loss for Deep Face Recognition.