避免雅可比矩阵计算过程中的警告

问题描述

我有一个经过训练的 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 循环实现过程中不断出现的两个警告。谁能帮我纠正我的代码或给我一个技巧来避免这些警告?

谢谢:)

解决方法

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

pip install -U gast==0.2.2.

安装这个,这将确保上面的警告不会出现。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...