-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Contrastive loss layer differs from loss equation #2308
Copy link
Copy link
Closed
Description
Hi,
I am a little bit confused of an implementation of contrastive loss function. As pointed in LeCun's paper
http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf the equation of this loss function should be: L = 0.5 * (1 - Y) * D^2 + 0.5 * Y * {max(0, margin - D)}^2. It's an equation 4 in the original paper. As far as I understood, source code of contrastive loss layer implements this loss function in other way. Here is a piece of code (lines 48-52 of contrastive_loss_layer.cpp file):
if (static_cast<int>(bottom[2]->cpu_data()[i])) { // similar pairs
loss += dist_sq_.cpu_data()[i];
} else { // dissimilar pairs
loss += std::max(margin-dist_sq_.cpu_data()[i], Dtype(0.0));
}
Is it a bug in implementation?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels