I am trying to learn about RL by implementing DQN with tensorflow. However, I am really stuck with tensorflow.. I just don't understand it. I think I have found the core of what I understand - I dont understand how I should pass placeholders to the network. When I run the code below I get the following error for the last (sess.run()) line:

Can anyone help me by saying what I am doing wrong (or maybe better - what it is that I dont understand) ?

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'obs' with dtype double and shape [4]
     [[{{node obs}}]]
import numpy as np
import tensorflow as tf
import keras.models
from keras.models import Sequential
from keras.layers import Activation, Dense
import gym


def createNN():
    model = Sequential()
    model.add(Dense(10, input_dim=OBS_SPACE))
    for i in range(1,4):
        model.add(Dense(10, activation = 'tanh'))
    model.add(Dense(ACTION_SPACE, activation = tf.nn.sigmoid))
    model.compile(loss='mse', optimizer='sgd')
    return model

env = gym.make('CartPole-v0')
obs = tf.placeholder(shape=DISC_OBS_SPACE, dtype=tf.float64, name = 'obs')
action = tf.placeholder(shape=1,dtype=tf.int32, name = 'action')
reward = tf.placeholder(shape=1, dtype= tf.float32, name = 'reward')
obs_next = tf.placeholder(shape=DISC_OBS_SPACE, dtype=tf.int32, name = 'obs_next')
nn = createNN()

sess.run(nn.predict(obs, steps=1), feed_dict={obs:env.reset()})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.