【问题标题】:Avoid Warnings during Jacobian Matrix Calculation在雅可比矩阵计算期间避免警告
【发布时间】:2021-02-26 15:24:57
【问题描述】:

我有一个训练有素的 LSTM 模型。我想计算输出 w.r.t 输入的雅可比矩阵。我写了以下代码:

data = pd.read_excel('filename')
a = data[:20]       #shape is (20,5)
b = data[50:70]     #shape is (20,5)  
A = [a,b]           #shape is (2,20,5)

At = tf.convert_to_tensor(A, np.float32)

with tf.GradientTape(persistent=True,watch_accessed_variables=True) as tape:

 tape.watch(At)
 y1 = model(At)
 
jacobian=tape.jacobian(y1,At)

我得到了所需的输出,但我收到了一些我无法理解的警告。如果它是一次,那是可以的。但我需要在运行超过 1000 次的 for 循环中计算雅可比矩阵。所以这些警告都会出现在 for 循环的每次迭代中。

WARNING:tensorflow:Entity <function pfor.<locals>.f at 0x000002A6E0129CA8> could not be transformed 
and will be executed as-is. Please report this to the AutgoGraph team. When filing the bug, set the 
verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: 
converting <function pfor.<locals>.f at 0x000002A6E0129CA8>: AssertionError: Bad argument number for 
Name: 3, expecting 4

WARNING: Entity <function pfor.<locals>.f at 0x000002A6E0129CA8> could not be transformed and will be 
executed as-is. Please report this to the AutgoGraph team. When filing the bug, set the verbosity to 
10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: converting 
<function pfor.<locals>.f at 0x000002A6E0129CA8>: AssertionError: Bad argument number for Name: 3, 
expecting 4

这是在 for 循环实现过程中不断出现的两个警告。谁能帮我纠正我的代码或给我一个技巧来避免这些警告?

谢谢你:)

【问题讨论】:

    标签: python warnings lstm gradient gradienttape


    【解决方案1】:

    我在朋友的帮助下找到了解决方案。

    pip install -U gast==0.2.2.
    

    安装它,这将确保不会出现上述警告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-24
      • 2020-07-14
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      • 2018-02-07
      相关资源
      最近更新 更多