python-3.xtensorflowreinforcement-learninglow-level-api

tf.gradients application on a function


x = tf.Placeholder(shape=[1,31,5,1])
def func(x):
    operations...
    return output

convolutionFunction = func(x)
sess = tf.Session()
gradientConv1 = gradientConv1 + sess.run(tf.gradients(tf.square(reward-convolutionFunction), weightsConv1))

gradientConv1 (numpy array of shape [2,2,1,32]) weightsConv1 (tensor variable of shape [2,2,1,32])

I'm getting an error such that "Placeholder should have a dtype of float and shape of [1,31,5,1]". It seems that it is showing me that I have not given a feed_dict to the function in sess.run? Please point me out to the error. Also is my way of differentiating with respect to each value correct.

reward is a scalar


Solution

  • gradientConv1 = gradientConv1 + sess.run(tf.gradients(tf.square(reward-convolutionFunction), weightsConv1), feed_dict={x: <valueOfPlaceholder> })
    

    where valueOfPlaceholder is the point at which we wish to evaluate the function

    Thanks to Andrey Akhmetov for pointing this out!