Kadenze / siamese_net

This package shows how to train a siamese network using Lasagne and Theano and includes network definitions for state-of-the-art networks including: DeepID, DeepID2, Chopra et. al, and Hani et. al. We also include one pre-trained model using a custom convolutional network.
Other
128 stars 37 forks source link

Contrastive Loss #7

Closed pvskand closed 7 years ago

pvskand commented 7 years ago

In the siamese_net.py in the contrastive_loss function I think the definition of the loss is implemented wrong.

The output of the function is the following: return T.mean(y * d + (1.0 - y) * T.maximum(margin - d, 0.0)) but according to the paper, if you see page 3 (bottom) according to the definition, the output must be: return T.mean((1.0 - y) * d + y * T.maximum(margin - d, 0.0))

pvskand commented 7 years ago

Aah I realised my mistake. return T.mean(y * d + (1.0 - y) * T.maximum(margin - d, 0.0)) is for having two similar features having the value 0 and return T.mean((1.0 - y) * d + y * T.maximum(margin - d, 0.0)) is for having 2 dissimilar features to give a value near to 0.

My bad! Closing this issue!