0

I'm writing a customized loss function, it looks like this:

loss = w1 * score1 + w2 * score2 + w3 * score3

I could see the final score (loss) in the process of model.fit now. But I would like to see the score1, score2, score3 as well.

How could I see the score1, score2, score3 results?

Ps. I know I could split the code and write multiple separate metric functions. But it will run the same calculation process twice (one for loss, one for metric). And the calculation of score1, score2, score3 is very time-consuming. Is there a better way for this task? Like pass some parameters from loss to metric? Or to history?

Thanks.

Patrick Lee
  • 155
  • 12

1 Answers1

1

You can pass separate loss functions to model.compile, along with their weights w1, w2, w3. This way, each individual loss term will be printed to the log along with their sum. For example:

model.compile(loss=[score1_fn, score2_fn, score3_fn], loss_weights=[w1, w2, w3], ...)

See How does keras handle multiple losses? for more details

zwang
  • 357
  • 1
  • 8
  • Thanks. But my functions `score1, score2, score3` share the same preprocess code. So in this way, the preprocess code will be run multiple times... It till cost much more time... – Patrick Lee Nov 15 '20 at 09:36