0

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?

  • The shape of the observation space is reflective of the image you're getting back from the environment. If you want to resize it, you need to have the same size of inputs in your target dimension. In other words, `210*160*3 != 88*80*1`. What you're asking is to convert a 210x160x3 image to a 88x80x1 image. You need some custom conversion function to do that. Or try changing your input layer of your DQN to 210x160x3. – deseuler May 24 '21 at 15:10

1 Answers1

0

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)