# Can siamese model trained with euclidean distance as distance metric use cosine similarity during inference?

If I have 3 embeddings Anchor, Positive, Negative from a Siamese model trained with Euclidean distance as distance metric for triplet loss.

During inference can cosine similarity similarity be used?

I have noticed if I calculate Euclidean distance with model from A, P, N results seem somewhat consistent with matching images getting smaller distance and non-matching images getting bigger distance in most cases.

In case I use cosine similarity on above embeddings I am unable to differentiate as similarity values between (A, P) and (A, N) seem almost equal or for different images one value seem higher vice versa.

Triplets were selected at random with no online hard, semi hard mining.

Wondering if I made mistake somewhere in implementation or the distance function in inference time should be same.

• Can you elaborate what you mean by "or for different images one value seem higher vice versa."? Feb 23 at 9:56
• Both for positive and negative image the values almost all around 0.9+. For example positive example 0.995, another 0.981 and for a negative image it can be 0.997, another 0.972. But calculating Euclidean distance similarity like, 1 /(1 + euclidean_dist(embedding1, embedding2) ) the positive images get expected higher values and negatives lower in most cases. Feb 23 at 12:00

Cosine distance has more interpretability than Euclidean distance, since cosine is bounded on $$[-1,1]$$, but needs to be applied with caution.