Compute external loss function but compute gradien

2019-08-04 10:32发布

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条回答
相关推荐>>
2楼-- · 2019-08-04 10:45

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

查看更多
登录 后发表回答