Scratch
Scratch

Reputation: 373

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!

Upvotes: 5

Views: 629

Answers (1)

jlanik
jlanik

Reputation: 939

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.

Upvotes: 1

Related Questions