我希望使用Keras中定义的各种损失函数来手动计算损失值。例如:
from keras.losses import binary_crossentropy
error=binary_crossentropy([1,2,3,4],[6,7,8,9])
给我错误提示
AttributeError: 'list' object has no attribute 'dtype'.
我希望以类似的方式使用其他 Keras 损失函数。 我有我的 y_pred 和 y_true 列表/数组。
我希望使用Keras中定义的各种损失函数来手动计算损失值。例如:
from keras.losses import binary_crossentropy
error=binary_crossentropy([1,2,3,4],[6,7,8,9])
给我错误提示
AttributeError: 'list' object has no attribute 'dtype'.
我希望以类似的方式使用其他 Keras 损失函数。 我有我的 y_pred 和 y_true 列表/数组。
K.variable()
来封装输入,使用K.eval()
来获取值。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]
AttributeError:'numpy.dtype'对象没有'base_dtype'属性
。 - Bhaskar Dhariyal