How to combine keras loss with other intermediate output loss using model.add_loss

92 views
Skip to first unread message

Ali Kasim

unread,
Apr 2, 2022, 7:01:43 PM4/2/22
to Keras-users

I am trying to reproduce COSTA/VAE code to make it run on tf2.x and Keras 2.x rather than 1.x. however, I am facing problem in combining Keras loss (which are tensors) with some intermediate layer outputs (which are KerasTensors).

the error is occured in this line 

gan.add_loss(gan_loss(y_true,y_pred,a,ap,b,bp)) <------ HERE IS THE PROBLEM gan.compile(optimizer=opt, loss=None)

Note: the code works fine if i removed either y_true,y_pred or a,ap,b,bp from the calculation of loss function, but it throws an error if i used them together in the calculation of loss function

the Question: What shall i send for y_true and y_pred as they are implicitly send if we follow the standard form of loss calculation like gan.compile(optimizer=opt, loss=gan_loss)

please have a look at the question with full code posted in stack overflow on this link: 

python - how to combine keras loss with other intermediate output loss using model.add_loss - Stack Overflow


Thanks for bearing this with me


Lance Norskog

unread,
Apr 2, 2022, 8:02:00 PM4/2/22
to Ali Kasim, Keras-users
Added a reply on StackOverflow.

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/3af1553f-8d34-451d-833a-88cf7d0f4ebdn%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA
Reply all
Reply to author
Forward
0 new messages