问题
I want to train a model for which the loss function can only be computed externally. So, I take the output of my last layer, compute some value externally and want to use this to update my network. Can I implement such a setup in tensorflow?
回答1:
Yes you can, you have to define your minimised loss out of the graph, for example:
loss = Network.loss(input_tensor)
loss_2 = out_function(loss)
And then you just have to specify :
train_step = optimizer.minimize(loss_2)
It should work
来源:https://stackoverflow.com/questions/52006002/compute-external-loss-function-but-compute-gradients-in-tensorflow