问题
I'm writing a custom loss function in Keras and just tripped over the following:
Why do Keras loss functions have to return one scalar per batch item rather than just one scalar?
I care about the cumulative loss for the whole batch, not about the loss per item, don't I?
回答1:
I think I figured it out: fit()
has an argument sample_weight
with which you can assign different weights to different samples in the batch. In order for this to work you need the loss function to return the loss per batch item.
来源:https://stackoverflow.com/questions/42895862/keras-why-do-loss-functions-have-to-return-one-scalar-per-batch-item-rather-tha