当我按如下所示制作自定义损失函数时:(与binary_crossentropy相同)
def custom_loss(y_true, y_pred):
return losses.binary_crossentropy(y_true, y_pred)
在keras / keras / losses.py中,binary_crossentropy是:
def binary_crossentropy(y_true, y_pred):
return K.mean(K.binary_crossentropy(y_true, y_pred), axis=-1)
当我跑步时:
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics= ['accuracy'])
model.compile(loss=losses.binary_crossentropy, optimizer=optimizer, metrics= ['accuracy'])
输出正确。
ETA: 6:20 - loss: 0.3697 - acc: 0.8343
如果我使用custom_loss:
model.compile(loss=custom_loss, optimizer=optimizer, metrics=['accuracy'])
输出不正确:
ETA: 10:49 - loss: 0.7651 - acc: 0.0694
我们可以看到准确性不正确。为什么?