Compute external loss function but compute gradients in tensorflow?

大城市里の小女人 提交于 2019-12-11 06:08:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!