# Defining the tf ops
prob_placeholder = tf.placeholder(tf.float32, shape=(2))
log_placeholder = tf.log(prob_placeholder)
grads_placeholder = tf.gradients(ys=tf.log(prob_placeholder), xs=model.weights)
# t is some index into the holders (which are lists)
# s is some state || p_a is some list of [p_1, 1 - p_1] || a_ is either 0 or 1 || r is 1
prob_ = tf_sess.run(prob_placeholder, {prob_placeholder: p_a})
log_ = tf_sess.run(log_placeholder, {prob_placeholder: prob_})
print(prob_, log_)
grads_ = tf_sess.run(grads_placeholder, {prob_placeholder: prob_})
Run Code Online (Sandbox Code Playgroud)
基本上我不确定为什么它会返回无.
TypeError: Fetch argument None has invalid type <type 'NoneType'>
Run Code Online (Sandbox Code Playgroud)
我已经尝试添加print语句了,我可以看到prob_和log_出来就好了,但我不确定导致上述问题的tf.gradients中发生了什么.
model.weights基本上是我正在使用的模型的权重.
prob_placeholder没有明确的依赖model.weights,即在功能上不依赖于model.weights您定义它们的方式。
因此,尽管从技术上讲梯度应该为零,但None由于TensorFlow中的技术原因而将其计算为梯度。
| 归档时间: |
|
| 查看次数: |
5437 次 |
| 最近记录: |