Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my tf_gradients returning None?

Tags:

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 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_})

Basically I'm not sure why it's returning None.

TypeError: Fetch argument None has invalid type <type 'NoneType'>

I've tried adding print statements and I can see prob_ and log_ come out just fine but I'm not sure what's happening in tf.gradients that is causing the issue above.

model.weights are basically the weights of the model that I'm using.

like image 983
IanQ Avatar asked Apr 25 '17 07:04

IanQ


1 Answers

prob_placeholder does not have any explicit dependence on model.weights, i.e. it is not functionally dependent on model.weights the way you have defined them.

Hence, though technically the gradient should be zero, it is computed as None due to technical reasons in TensorFlow.

like image 132
musically_ut Avatar answered Nov 12 '22 09:11

musically_ut