I want to use the various loss function defined in keras for calculating the loss value manually. For example:
from keras.losses import binary_crossentropy
e
You can use K.variable()
to wrap the inputs and use K.eval()
to get the value.
from keras.losses import binary_crossentropy
from keras import backend as K
y_true = K.variable(np.array([[1], [0], [1], [1]]))
y_pred = K.variable(np.array([[0.5], [0.6], [0.7], [0.8]]))
error = K.eval(binary_crossentropy(y_true, y_pred))
print(error)
[ 0.69314718 0.91629082 0.35667494 0.22314353]