【发布时间】:2022-01-03 20:08:51
【问题描述】:
我目前正在谷歌 CoLab 上使用 NeuralODE,我尝试使用命令“defun”,但没有成功。我使用的是 NeuralODE 要求的 Tensorflow 版本 1.x,但是当我尝试使用 tf.defun 时,我收到错误“AttributeError:模块 'tensorflow' 没有属性 'defun'。我怎样才能真正进入 defun ?
这是我需要的特定代码
def compute_gradients_and_update():
with tf.GradientTape() as g:
hN = neural_ode.forward(h0_var)
g.watch(hN)
loss = tf.reduce_sum((hN_target - hN)**2)
dLoss = g.gradient(loss, hN) # same what 2 * (hN_target - hN)
h0_reconstruction, dfdh0, dWeights = neural_ode.backward(hN, dLoss)
optimizer.apply_gradients([(dfdh0, h0_var)])
return loss
compute_gradients_and_update = tf.defun(compute_gradients_and_update)
我在 stackoverflow 上看到过类似的问题,但解决方案都非常具体,我还没有看到任何关于“defun”的具体内容。我希望这是有道理的,我是初学者。
谢谢!
【问题讨论】:
标签: python tensorflow