Skip to content

Instantly share code, notes, and snippets.

@monk1337
Last active May 13, 2018 06:57
Show Gist options
  • Save monk1337/1c6bda83738d6326d64f502f477f0953 to your computer and use it in GitHub Desktop.
Save monk1337/1c6bda83738d6326d64f502f477f0953 to your computer and use it in GitHub Desktop.
def contrastive_loss(self, y, d, batch_size):
tmp = y * tf.square(d)
# tmp= tf.mul(y,tf.square(d))
tmp2 = (1 - y) * tf.square(tf.maximum((1 - d), 0))
return tf.reduce_sum(tmp + tmp2) / batch_size / 2
# self.scores = logits
with tf.name_scope("loss"):
self.loss = tf.nn.sigmoid_cross_entropy_with_logits(labels=self.input_y, logits=self.scores)
self.cost = tf.reduce_mean(self.loss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment