【问题标题】:NeuralODE Python - "AttributeError: module 'tensorflow' has no attribute 'defun' "NeuralODE Python - “AttributeError:模块‘tensorflow’没有属性‘defun’”
【发布时间】: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


    【解决方案1】:

    Tensorflow 没有名为 defun 的属性。

    如果您使用的是 tf 1.x,请使用

    tf.contrib.eager.defun
    

    【讨论】:

      猜你喜欢
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-08
      • 2020-02-04
      • 2020-02-12
      • 2019-01-10
      • 2019-10-01
      相关资源
      最近更新 更多