Hello,
I want to create a model with multiple inputs and outputs in Gluon. I have some experience with Keras framework, and to do this type of model with Keras es very simple. However, I can’t find an example to do such a model with Gluon.
Is there any example with Gluon? Where I can find it?
Best regards
Oh, thank for the quick response, it is very helpful. I still ask for an example having multiple loss. For example
loss = loss1 + loss2+ …
loss.backward()
Will it be a solution? I mean, Will mxnet compute the gradient for loss1, loss2 by only calling loss.backward? or I need to do loss1.backward(), loss2.backward()… for every loss my model has.
Sorry, I know this could be trivial, but I don’t have experience with autograd.
1 Like
Yes, you can add the losses as you say. E.g. assume you have a model with multiple inputs net(input1,input2)
that produces multiple outputs:
with autograd.record(): # edit here, sorry, for gradient calculation, you need to use record
out1, out2 = net(input1,input2)
loss1 = some_loss(out1,some_label1)
loss2 = some_other_loss(out2,some_label2)
loss = loss1 + loss2
loss.backward() # calculates gradient from the composite loss function
...
1 Like
Oh, it is nice, thank so much @feevos!
1 Like