Keras: Why do loss functions have to return one scalar per batch item rather than just one scalar?

蓝咒 提交于 2020-01-05 04:05:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!