sounakdey/SigNet

Accuracy decreasing during training phase

Closed this issue · 2 comments

Hello again sounakdey,

I run your code again, and in the training phase i noted tha the accuracy decreased constantly In less than one epoch.

I found it strange. So i searched in the keras group for answers and i found that the siamese example had another errors. And i made some more changes.

I changed this:

def eucl_dist_output_shape(shapes):
shape1, shape2 = shapes
return (shape1[0], 1)

def contrastive_loss(y_true, y_pred):
'''Contrastive loss from Hadsell-et-al.'06
http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf
'''
margin = 1
K.mean(y_true * K.square(y_pred) + (1 - y_true) * K.square(K.maximum(margin - y_pred, 0)))

for this:

def eucl_dist_output_shape(shapes):
shape1, shape2 = shapes
return (shape1[1], 0)

def contrastive_loss(y_true, y_pred):
'''Contrastive loss from Hadsell-et-al.'06
http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf
'''
margin = 1
return K.mean((1 - y_true) * K.square(y_pred) + y_true * K.square(K.maximum(margin - y_pred, 0)))

And now the accuracy in training is ok.

You passed for something like this?

In the loss I see the change you made is (1 - y_true) in place of y_true.. Isn't it?... You should be careful about the lables you give to similar and dissimilar images (i.e. 0 and1) which means you are putting the negative ones outside the margin defined...

i change the loss function too,but the accu is also bad , and the val loss do not decrease when it is about 0.35 but if i do not change a lot of the predict result is more than 1. i think it is not normal ,so i wanna ask if it is neccesary to change loss function.