Tensorflow:opt.compute_gradients() 返回的值不同于 opt.apply_gradients() 的权重差异

标签 tensorflow

问题:在 TensorFlow 网络中以最有效的方式获得权重增量的最有效方法是什么?

背景 :我已经按如下方式连接了运算符(operator)(感谢这个 SO question ):

self.cost = `网络的其余部分`
self.rmsprop = tf.train.RMSPropOptimizer(lr,rms_decay,0.0,rms_eps)
self.comp_grads = self.rmsprop.compute_gradients(self.cost)
self.grad_placeholder = [(tf.placeholder("float", shape=grad[1].get_shape(), name="grad_placeholder"), grad[1]) for grad in self.comp_grads]
self.apply_grads = self.rmsprop.apply_gradients(self.grad_placeholder)

现在,为了提供信息,我运行以下命令:

feed_dict = `训练变量`
grad_vals = self.sess.run([grad[0] for grad in self.comp_grads], feed_dict=feed_dict)

feed_dict2 = `feed_dict 加上添加到 self.grad_placeholder` 的梯度值
self.sess.run(self.apply_grads,feed_dict=feed_dict2)
run(self.apply_grads)的命令将更新网络权重,但是当我计算开始和结束权重的差异( run(self.w1) )时,这些数字与存储在 grad_vals[0] 中的数字不同.我认为这是因为 RMSPropOptimizer 对原始梯度做了更多的工作,但我不确定是什么,或者在哪里可以找到它的作用。

所以回到问题:如何以最有效的方式获得权重的增量?我是否坚持运行 self.w1.eval(sess)多次获得权重并计算差异? tf.RMSPropOptimizer 有什么我遗漏的地方吗?功能。

谢谢!

最佳答案

RMSprop 不会从参数中减去梯度,而是使用包含以下组合的更复杂的公式:

  • 一个动量,如果对应的参数不是 0
  • 梯度步骤,通过梯度的平方平均值的平方根非均匀地(在每个坐标上)重新缩放。

  • 更多信息可以引用these slidesthis recent paper .

    delta 首先在内存中由槽变量“momentum”中的 tensorflow 计算,然后变量被更新(参见 the C++ operator)。
    因此,您应该能够访问它并使用 delta_w1 = self.rmsprop.get_slot(self.w1, 'momentum') 构造一个增量节点。 . (我还没有尝试过。)

    关于Tensorflow:opt.compute_gradients() 返回的值不同于 opt.apply_gradients() 的权重差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37123745/

    相关文章:

    python - 使用 Keras LSTM 进行多对多分类

    python - tensorflow :如何创建一个与占位符形状相同的常量张量

    tensorflow - tensorflow 中的常规模型检查点和保存的模型有什么区别?

    python - 限制 Keras 中使用的核心数

    machine-learning - 每次显着下降之间困惑度计算都会上升

    python - tensorflow 概率中的重新参数化 : tf. GradientTape() 不计算相对于分布均值的梯度

    Tensorflow (tfjs) - 保存经过训练的模型

    python - Pip 在 macOS 上找不到 python 3.6 的 tensorflow

    python-3.x - 为什么在 Mac 上加载 tensorflow 会导致 "Process finished with exit code 132 (interrupted by signal 4: SIGILL)"?

    python - Tensorflow:从输入到输出的梯度计算