我有一个训练有素的 LSTM 模型。我想计算输出 wrt 输入的雅可比矩阵。我写了以下代码:
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 循环实现过程中不断出现的两个警告。任何人都可以帮助我纠正我的代码或给我一个避免这些警告的技巧吗?
谢谢 :)