本文介绍了计算外部损失函数,但计算张量流中的梯度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想训练一个只能从外部计算损失函数的模型.因此,我获取了最后一层的输出,在外部计算了一些值,并希望使用它来更新我的网络.我可以在tensorflow中实现这样的设置吗?
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?
推荐答案
是的,您必须在图中定义最小化的损失,例如:
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)
然后只需指定:
train_step = optimizer.minimize(loss_2)
应该可以
这篇关于计算外部损失函数,但计算张量流中的梯度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!