Skip to content

Instantly share code, notes, and snippets.

@salihkaragoz
Last active April 20, 2018 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salihkaragoz/333270428876532e5aaac55cc0c37386 to your computer and use it in GitHub Desktop.
Save salihkaragoz/333270428876532e5aaac55cc0c37386 to your computer and use it in GitHub Desktop.
keras focal loss theano backend
y_true = 2
y_pred = 0.2
if(K.backend()=="tensorflow"):
import tensorflow as tf
sess= tf.Session()
with tf.device('/cpu:0'):
pt = tf.where(tf.equal(y_true, 1), y_pred, 1 - y_pred)
print(sess.run(pt))
if(K.backend()=="theano"):
import theano as th
x = th.tensor.dscalar('x')
y = th.tensor.dscalar('y')
pt = th.tensor.where(th.tensor.eq(x, 1), y, 1 - y)
f = th.function([x, y], pt)
print(f(y_true, y_pred))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment