Last active
April 20, 2018 13:05
-
-
Save salihkaragoz/333270428876532e5aaac55cc0c37386 to your computer and use it in GitHub Desktop.
keras focal loss theano backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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