python - 得到“ValueError:磁带仍在录制,如果您在计算梯度磁带内的雅可比时尝试重新输入已经激活的磁带,可能会发生这种情况”
问题描述
我的损失函数需要计算雅可比矩阵行列式的对数。所以,我写了下面的代码
def gradient_update(self, X, optimizer):
with tf.GradientTape() as t, tf.GradientTape() as j:
Y = self(X)
out = -self.distribution(Y) - tf.math.log(tf.linalg.det(j.jacobian(Y, X)))
Loss = tf.math.reduce_sum(out)
grads = t.gradient(Loss, self.trainable_weights)
optimizer.apply_gradients(zip(grads, self.trainable_weights))
return Loss
这给了我以下错误
ValueError: Tape is still recording, This can happen if you try to re-enter an already-active tape.
解决方案
推荐阅读
- .net - SharpShooter 报告在奇数页上带有静态文本的双面打印
- tabulator - Tabulator.js 将分页下拉菜单从页面上移开(bootstrap4)
- rust - 如何从文件中读取结构,替换 self 的内容?
- linux - ANSIBLE“错误!“主机”字段是必需的,但未设置”
- prolog - 在 List Prolog 中显示最后一个元素
- r - 闪亮 - 插入到 navbarPage 的链接
- java - 如何在不设置 array.lenght-1 的情况下在简单的快速排序中修复 java.lang.StackOverflowError?
- powershell - 如何使用 PATS 从 TFS 构建定义中的内联 Powershell 脚本执行 powershell 文件
- haxe - 如何循环形状的输出
- javascript - 如何将带有 lang="en" 的文档调用到 javascript?