I am trying to implement the marginal loss introduced in the paper [1]. So far this is what I have done.
def marginal_loss(model1, model2, y, margin, threshold):
margin_ = 1/(tf.pow(margin,2)-margin)
tmp = (1. - y)
euc_dist = tf.sqrt(tf.reduce_sum(tf.pow(model1-model2, 2), 1, keep_dims=True))
thres_dist = threshold - euc_dist
mul_val = tf.multiply(tmp, thres_dist)
sum_ = tf.reduce_sum(mul_val)
return tf.multiply(margin_, sum_)
However, after some epochs, the value goes to nan. I am not sure what mistake I made. Furthermore, I have used 1 instead of epsilon (described in the paper) because its value was not clear. Similarly, the exact threshold value is also not known.
Thanks for any help.
[1] https://ibug.doc.ic.ac.uk/media/uploads/documents/deng_marginal_loss_for_cvpr_2017_paper.pdf