Tensorflow 为什么我的TFU梯度没有返回?

Tensorflow 为什么我的TFU梯度没有返回?,tensorflow,Tensorflow,基本上我不知道为什么它没有返回 # 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 hol

基本上我不知道为什么它没有返回

# 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_})
TypeError:Fetch参数None的类型无效
我已经尝试添加打印语句,我可以看到prob_uuu和log_uuuu的结果很好,但我不确定在tf.gradients中发生了什么导致上述问题


model.weights基本上是我正在使用的模型的权重。

prob\u占位符
model.weights
没有任何明确的依赖性,即它在功能上不依赖于
model.weights
您定义它们的方式


因此,虽然从技术上讲梯度应该为零,但由于。

太棒了,它被计算为
None
!所以有一种方法是使model.output成为prob_占位符吗?这样,prob_占位符与model.weights?@user162264间接相关。通常的方法是将输出标签保留在
tf.placeholder
中,然后计算一个损失函数,该函数接受真实标签和NN的输出,并计算一个值。然后我们可以计算模型变量的损失梯度w.r.t。
TypeError: Fetch argument None has invalid type <type 'NoneType'>