如何解决避免雅可比矩阵计算过程中的警告
我有一个经过训练的 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.
安装这个,这将确保上面的警告不会出现。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。