Examples · references/similarity
Similarity Learning Using Triplet Loss
In this reference, we use triplet loss to learn embeddings which can be used to differentiate images. This learning technique was popularized by FaceNet: A Unified Embedding for Face Recognition and Clustering and has been quite effective in learning embeddings to differentiate between faces.
This reference can be directly applied to the following use cases:
- You have an unknown number of classes and would like to train a model to learn how to differentiate between them.
- You want to train a model to learn a distance-based metric between samples. For example, learning a distance-based similarity measure between faces.
Training
By default, the training script trains ResNet50 on the FashionMNIST Dataset to learn image embeddings which can be used to differentiate between images by measuring the euclidean distance between embeddings. This can be changed as per your requirements.
Image embeddings of the same class should be 'close' to each other, while image embeddings between different classes should be 'far' away.
To run the training script:
python train.py -h # Lists all optional arguments
python train.py # Runs training script with default argsRunning the training script as is should yield 97% accuracy on the FMNIST test set within 10 epochs.