Tensorflow:使用clip_by_norm或clip_by_global_norm时如何确定clip_norm的值?
Tensorflow: How to determine the value of clip_norm when using clip_by_norm or clip_by_global_norm?
我正在尝试找出在将 clip_by_norm or clip_by_global_norm 与 Tensorboard 一起使用时如何确定 clip_norm
的值。
在Tensorflow中,我们可以使用优化器compute_gradients
获取梯度并将其添加到tf.summary.histogram. In Tensorboard, we can observe the range of the gradient in the DISTRIBUTIONS
tab. Then we can determine the clip_value
range when using clip_by_value.
另一方面,我该如何calculate/display Tensorboard中的范数或全局范数来确定clip_norm
的值?
要在 Tensorboard 中查看范数或全局范数,您可以手动计算它。
对于范数(非全局),您可以像往常一样使用 compute_gradients
获得梯度并使用 tf.norm
. This gives you a scalar value. You can add it to Tensorboard using tf.summary.scalar
.
计算梯度 l2 范数
对于全局范数,您可以使用 tf.global_norm
计算它,然后将其添加到 Tensorboard(也是标量摘要)。
编辑:
请注意 tf.norm
需要单个张量。因此,您需要为每个梯度张量计算范数并添加到 Tensorboard。与使用 tf.summary.histogram
查看值时的操作相同。
我正在尝试找出在将 clip_by_norm or clip_by_global_norm 与 Tensorboard 一起使用时如何确定 clip_norm
的值。
在Tensorflow中,我们可以使用优化器compute_gradients
获取梯度并将其添加到tf.summary.histogram. In Tensorboard, we can observe the range of the gradient in the DISTRIBUTIONS
tab. Then we can determine the clip_value
range when using clip_by_value.
另一方面,我该如何calculate/display Tensorboard中的范数或全局范数来确定clip_norm
的值?
要在 Tensorboard 中查看范数或全局范数,您可以手动计算它。
对于范数(非全局),您可以像往常一样使用 compute_gradients
获得梯度并使用 tf.norm
. This gives you a scalar value. You can add it to Tensorboard using tf.summary.scalar
.
对于全局范数,您可以使用 tf.global_norm
计算它,然后将其添加到 Tensorboard(也是标量摘要)。
编辑:
请注意 tf.norm
需要单个张量。因此,您需要为每个梯度张量计算范数并添加到 Tensorboard。与使用 tf.summary.histogram
查看值时的操作相同。