How to find loss values using keras?

后端 未结 1 1922
忘了有多久
忘了有多久 2021-01-04 03:26

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         


        
相关标签:
1条回答
  • 2021-01-04 04:02

    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]
    
    0 讨论(0)
提交回复
热议问题