加权自定义损失keras
Weighted custom loss keras
您可以像这样在 Keras 中使用加权 MSE
model.fit(sample_weight=weights, loss='mse', ...)
我想使用加权 RMSE 但是 Keras 库没有 rmse,我自己写的
def root_mean_squared_error(y_true, y_pred):
return K.sqrt(K.mean(K.square(y_pred - y_true)))
但是如何使用权重呢?
从 documentation 看来,它是自动完成的:
Creating custom losses:
Any callable with the signature loss_fn(y_true, y_pred) that returns an array of losses (one of sample in the input batch) can be passed to compile() as a loss. Note that sample weighting is automatically supported for any such loss.
您可以像这样在 Keras 中使用加权 MSE
model.fit(sample_weight=weights, loss='mse', ...)
我想使用加权 RMSE 但是 Keras 库没有 rmse,我自己写的
def root_mean_squared_error(y_true, y_pred):
return K.sqrt(K.mean(K.square(y_pred - y_true)))
但是如何使用权重呢?
从 documentation 看来,它是自动完成的:
Creating custom losses: Any callable with the signature loss_fn(y_true, y_pred) that returns an array of losses (one of sample in the input batch) can be passed to compile() as a loss. Note that sample weighting is automatically supported for any such loss.