Resize a state of a gym environment composed by 4 frames (atari environment)

2.7k views Asked by At

I'm developing an Autonomous Agent based on DQN. I am using the gym library to make the environments that I want to test, but I'm stuck in processing the frames of the state. The state that the gym environment returns, using the FrameStack wrapper, has the following observation space:

env = gym.make('Bowling-v0')
env = gym.wrappers.FrameStack(env, 4)
print(env.observation_space)

Box(0, 255, (4, 210, 160, 3), uint8)

I want the observation space to be Box(0, 255, (4, 88, 80, 1), uint8). How can I do? I've tried to use another wrapper like this:

env = gym.wrappers.ResizeObservation(env, (4, 88, 80, 1))
print(env.observation_space)

But the observation space resulting is Box(0, 255, (4, 88, 80, 1, 160, 3), uint8). What am I doing wrong?

1

There are 1 answers

0
Luca Varini On BEST ANSWER

Fixed! I was just doing it in the wrong way.

env = gym.make('Bowling-v0')
print(env.observation_space)

Box(0, 255, (210, 160, 3), uint8)

First must be applied the resize and then the stacking only after the resize!

env = gym.wrappers.ResizeObservation(env, (88, 80))
print(env.observation_space)

Box(0, 255, (88, 80, 3), uint8)

So now we can proceed with the stacking with the FrameStack wrapper

env = gym.wrappers.FrameStack(env, 4)
print(env.observation_space)

Box(0, 255, (4, 88, 80, 3), uint8)