How to interpret the observations of RAM environments in OpenAI gym?

Viewed 5624

In some OpenAI gym environments, there is a "ram" version. For example: Breakout-v0 and Breakout-ram-v0.

Using Breakout-ram-v0, each observation is an array of length 128.

Question: How can I transform an observation of Breakout-v0 (which is a 160 x 210 image) into the form of an observation of Breakout-ram-v0 (which is an array of length 128)?

My idea is to train a model on the Breakout-ram-v0 and display the trained model playing using the Breakout-v0 environment.

4 Answers

My idea is to train a model on the Breakout-ram-v0 and display the trained model playing using the Breakout-v0 environment.

Similar to erosten's answer: If your environment is

env = gym.make('Breakout-ram-v0')
env.reset()

and you want pixels, you're looking for

pixels = env.unwrapped._get_image()

You can simply use ram environment of Atari for training and call the wrappers object to automatically save the trained videos.

import gym
from gym import wrappers
env = gym.make('SpaceInvaders-ram-v0')
env = wrappers.Monitor(env, "/path/to/folder/", force=True)
class(Policy):
    "Do your thing"


train_function() #call your train function

While the above answer is correct in terms of reinforcement learning strategy and the inability to directly convert ram to image or vice versa, to grab the ram state from an image environment, you can use

# this is an image based environment
env = gym.make('Breakout-v0')
env.reset()

# put in the 0 action 
observation_image, reward, done, info = env.step(0)

# get the ram observation with the code below
observation_ram = env.unwrapped._get_ram()
Related