1
# 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_})
基本上我不知道它为什么返回无。为什么我的tf_gradients返回None?
TypeError: Fetch argument None has invalid type <type 'NoneType'>
我试着添加打印语句,我可以看到prob_和LOG_出来就好了,但我不知道正在发生的事情,是造成上述问题的tf.gradients。
model.weights基本上是我正在使用的模型的权重。
太棒了!那么一种方法是让model.output是prob_placeholder?这样prob_placeholder与model.weights间接相关吗? – user49593
@ user162264通常的方法是将输出标签保存在'tf.placeholder'中,然后计算一个损失函数,该函数采用NN的真实标签和输出并计算一个值。然后可以计算损失w.r.t的梯度。模型变量。 –