如何添加张量流损失函数?

how to add tensorflow loss functions?

我不能把这两个损失加起来如下

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

错误是:

TypeError:+ 不支持的操作数类型:'BinaryCrossentropy' 和 'BinaryCrossentropy'

您可以将它们作为多次损失添加到 model.compile

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

这转换为 final_loss = l1*loss1 + l2*loss2。只需将 l1l2 设置为 1.