I am trying to run the chech_env function in gym (OpenAI version), however it's failing on an assertion error suggesting the environment isn't configured correctly. Specifically it's saying AssertionError: The observation returned by the
reset() method should be a single value, not a tuple
I've built a custom gym environment, and currently I have an observation_space that looks like this:
from gym import spaces
# class def, etc, this is not a stand alone func
def __init__(self):
self.camera_height = 210
self.camera_width = 160
# lots of environment setup
self.action_space = spaces.Box(
low=np.array([0, -1.0]), high=np.array([1, 1.0]),
shape=(2,), dtype=np.float32)
self.observation_space = spaces.Box(
low=0, high=255,
shape=(self.camera_height, self.camera_width, 3),
dtype=np.uint8)
And I'm returning from a get_obs() function, which is just returning an empty array of zeros for now.
def get_ob(self):
state = np.zeros((self.camera_width, self.camera_height, 3), np.uint8)
return state
And then those results are return directly in the return for reset(self), as such:
def reset(self):
# lots of set up code here
self.obs = self.get_ob()
return self.obs, {'arg1': 0}
And I'm running the check_env function, which should test to make sure everything is working
import gym
import my_custom_env
from stable_baselines3.common.env_checker import check_env
env = gym.make('my_custom_env-v0')
check_env(env)
However it keeps complaining that it shouldn't be a Tuple, which is confusing since there are no Tuples in my code at all. The full error looks like this:
Traceback (most recent call last):
File "check_env.py", line 10, in <module>
check_env(env)
File "/home/cannon-art/.local/lib/python3.8/site-packages/stable_baselines3/common/env_checker.py", line 400, in check_env
_check_returned_values(env, observation_space, action_space)
File "/home/cannon-art/.local/lib/python3.8/site-packages/stable_baselines3/common/env_checker.py", line 246, in _check_returned_values
_check_obs(obs, observation_space, "reset")
File "/home/cannon-art/.local/lib/python3.8/site-packages/stable_baselines3/common/env_checker.py", line 162, in _check_obs
assert not isinstance(
AssertionError: The observation returned by the `reset()` method should be a single value, not a tuple
Printing out self.observation.shape and state.shape give me the same sizes and they look the same as well. I'm really at a loss here and would appreciate any thoughts you may have. Thanks!!