我是Keras的新手。我想知道某些实例的丢失。所以我得到了这些数据实例的y_true和y_pred。我想调用损失函数来计算损失,但只得到Tensor(“ Mean_5:0”,shape =(),dtype = float32)。如何评估张量的值?通过调用los.eval()类似于张量流吗?
y_pred的计算依据:
y_pred = self.model.predict(x, batch_size=self.batch_size)
y_true也是可用列表。
如何使用binary_crossentropy()?
您几乎得到了答案。
from keras import backend
from keras.losses import binary_crossentropy
y_true = backend.variable(y_true)
y_pred = backend.variable(y_pred)
# calculate the average cross-entropy
mean_ce = backend.eval(binary_crossentropy(y_true, y_pred))
print('Average Cross Entropy: %.3f nats' % mean_ce)