Home > Mobile >  how to add tensorflow loss functions?
how to add tensorflow loss functions?

Time:10-02

I can not add these two losses as follows

real_loss = tf.losses.BinaryCrossentropy(tf.ones_like(train_images[0]),train_images[0])
fake_loss = tf.losses.BinaryCrossentropy(tf.zeros_like(train_images[0]),train_images[0])
fake_loss real_loss

the error is:

TypeError: unsupported operand type(s) for : 'BinaryCrossentropy' and 'BinaryCrossentropy'

CodePudding user response:

You can just add them as multiple losses in model.compile

model.compile(loss = [loss1,loss2], loss_weights = [l1,l2], ...)

This translates to final_loss = l1*loss1 l2*loss2. Just set l1 and l2 as 1.

  • Related