Data/Machine learning

Cosine-similarity Classifier; PyTorch Implementation

DS-Lee 2021. 3. 17. 11:10

Cosine-similarity Classifier introduced in [S. Gidaris et al., 2018] is implemented here. The cosine-similarity classifier is compared to the linear-softmax classifier. The codes can be found in my Github. [W. Chen et al., 2020] verifies the performance improvement by the cosine-similarity classifier in the few-shot learning regime.

Result; In the one-shot learning regime

The models are trained on the MNIST dataset in which data corresponding to 7 is left out as a novel class. During the test, one data for the novel class 7 is given, and the classification accuracies of both models are presented:

(Left) cosine-similarity classifier, (Right) linear classifier

Since the cosine-similarity classifier takes the prototype approach, it doesn't need to be fine-tuned. Therefore, it does not degrade its classification performance for the base classes. However, the linear classifier needs to be fine-tuned and degrades its original performance for the base classes.