Deep Reinforcement Learning for Atari Games Python Tutorial | AI Plays Space Invaders

Nicholas Renotte · 71K views · 2020 · 38:14

Open on YouTube

Machine learning & deep learningPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the tutorial they followed when asking or answering Keras-RL and OpenAI Gym questions, especially when version mismatches or graph errors break the code.

Recommended by 1 people across 1 different months, 2021 to 2022.

What it is

A 38-minute Python tutorial by Nicholas Renotte that builds a deep reinforcement learning agent to play Atari Space Invaders. It walks through creating an OpenAI Gym Atari environment, building a TensorFlow/Keras model, and training and testing a DQN agent with Keras-RL.

What people said

Recommends Mehdi LAMRANI · 2022-07 · Stack Overflow · on “KerasRL : Value Error: Tensor must be from same graph as Tensor”

He literally adresses this exact error 3mn later in that same video [this video] if you care waching it. Basically deleting the model ( del model ) and rebuildint it does the trick

Cites abdelmoumen · 2021-12 · Stack Overflow · on “real tme keras rl DQN predictions”

hello everyone I followed that tutorial [this video] to train a DQN Agent everything works env = gym.make('CartPole-v0') states = env.observation_space.shape[0] actions = env.action_space.n episodes = 10 for episode in range(1, episodes+1): state = env.reset() done = False score = 0 while not done: env.render() action = random.choice([0,1]) n_state, reward, done, info = env.step(action) score+=reward print('Episode:{} Score:{}'.format(episode, score)) now rather than make a random choice I want to use the DQN without having to do dqn.test(env, steps=10) something like dqn.predict but I did not find that in their documentation can you help please

Cites Anwesh · 2022-03 · Stack Overflow · on “KerasRL : Value Error: Tensor must be from same graph as Tensor”

I am trying to build a RL model to play the Atari Pinball game while following Nicholas Renotte's video [this video] . However, when I try to build the final KerasRL model I get the following error : ValueError: Tensor("dense/kernel/Read/ReadVariableOp:0", shape=(256, 9), dtype=float32) must be from the same graph as Tensor("dense_4/Relu:0", shape=(None, 256), dtype=float32) (graphs are <tensorflow.python.framework.ops.Graph object at 0x000001DA9F3E0A90> and FuncGraph(name=keras_graph, id=2038356824176)). The code: def build_model(height, width, channels, actions): model = Sequential() model.add(Convolution2D(32, (8,8), strides=(4,4), activation='relu', input_shape=(3,height, width, channels))) m

Cites Bob Jones · 2022-10 · Stack Overflow · on “Exception has occurred: AttributeError 'int' object has no attribute 'shape' when calling dqn.fit()”

I'm having the same issue (following this tutorial: [this video] ). Just following the error, my best guess is something is up with Python version, keras, gym or even tensorflow, as seems to often be the case with these tutorials from even a year ago. For instance, in the tutorial, he's using Python 3.7--you're using Python 3.10, and I'm using Python 3.9. If it's not that, then maybe it's a keras version change, or maybe the observation returned by Gym is different (I don't know what version you're using, but I'm using 0.26.2, and the tutorial is using 0.18.0). Anyway, that's my best guess. Unless someone here has immediate knowledge of what changes are leading to our issues, the best course of a