在雅可比矩阵计算时避免警告



我有一个训练好的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)

我得到了所需的输出,但我得到了一些我无法理解的警告。如果只是一次,那就随他们去吧。但是我需要在for循环中计算雅可比矩阵它运行了1000次。因此,这些警告会出现在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.

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

最新更新