I want to calculate the gradients, my model is a little bit difficult, it can be represented as the following loss function:
loss=label1*f1(x)+label2*f2(x)+label3*f3(x)
x is the feature of model, f1 is one model which is predicting one logit, you can see that there are three models and I want to sum them together. In order for easy understanding, loss function can be written as
loss=-tf.reduce_sum(label * tf.log(x), axis=1)
but I have three different lables and different models and same feature. I find tf.GradientTape is a easy way to calculate the gradients(https://www.tensorflow.org/tutorials/eager/custom_training_walkthrough), but they use
loss_value, grads = grad(model, features, labels)
there is only one model ,one feature list and one labels list.but how to solve the above multiclass problem?