Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do keras loss have to output one scalar per batch or one scalar for the whole batch ?

I read in a related question that keras custom loss function have to return one scalar per batch item.

I wrote a loss function that output a scalar for the whole batch and the network seems to converge. However I am not able to find any documentation on this or what exactly happens in the code. Is there a broadcasting done somewhere ? What happens if I add sample weights? Does someone has a pointer to where the magic happens ?

Thanks!

like image 369
Scratch Avatar asked Nov 07 '22 02:11

Scratch


1 Answers

In general you can often use a scalar in place of a vector and this will be interpreted as a vector that is filled with this value ( e.g 1 is interpreted as 1,1,1,1 ). So if the result of your loss function for a batch is x, it is interpreted as if you were saying that loss for each item in the batch is x.

like image 95
jlanik Avatar answered Nov 14 '22 22:11

jlanik