[Bug] get_obs_shape returns wrong shape for MultiBinary spaces
See original GitHub issueImportant Note: We do not do technical support, nor consulting and don’t answer personal questions per email. Please post your question on the RL Discord, Reddit or Stack Overflow in that case.
If your issue is related to a custom gym environment, please use the custom gym env template.
🐛 Bug
stable_baselines3.common.preprocessing.get_obs_shape
returns the wrong shape when a MultiBinary spaces is multi-dimensions.
To Reproduce
Steps to reproduce the behavior.
Please try to provide a minimal example to reproduce the bug. Error messages and stack traces are also helpful.
from gym import spaces
from stable_baselines3.common.preprocessing import get_obs_shape
test_multi = spaces.MultiBinary([5, 4, 5])
get_obs_shape(test_multi)
151 elif isinstance(observation_space, spaces.MultiBinary):
152 # Number of binary features
--> 153 return (int(observation_space.n),)
154 elif isinstance(observation_space, spaces.Dict):
155 return {key: get_obs_shape(subspace) for (key, subspace) in observation_space.spaces.items()}
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
Expected behavior
get_obs_shape should returnobservation_space.shape
not int(observation_space.n)
### System Info
Describe the characteristic of your environment:
- Describe how the library was installed (pip, docker, source, …): pip
- GPU models and configuration: none
- Python version: 3.7.
- PyTorch version: 1.9.0
- Gym version" 0.18.3
Checklist
- I have checked that there is no similar issue in the repo (required)
- I have read the documentation (required)
- I have provided a minimal working example to reproduce the bug (required)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (2 by maintainers)
Top Results From Across the Web
stable_baselines3.common.utils - Stable Baselines3
shape ) == 1: return True else: raise ValueError( f"Error: Unexpected observation shape {observation.shape} for " + "Discrete environment, please use (1,) or...
Read more >Error while defining observation space in gym custom ...
General answer: minimal example of custom env with Box observation space in gym. dtype in box and observation should be same. Here both...
Read more >Spaces - Gym Documentation - Manuel Goulão
A sampled actions from the space Return the shape of the space as an immutable property. Return the data type of this space....
Read more >Spaces - Gym Documentation
Return the shape of the space as an immutable property. ... from gym.spaces import Box, Dict, Discrete, MultiBinary, MultiDiscrete >>> Dict( ... {...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Despite the doc, turns out gym itself also dislike N-Dim MultiBinary,
https://github.com/openai/gym/blob/4ede9280f9c477f1ca09929d10cdc1e1ba1129f1/gym/spaces/utils.py#L28
So I guess a wrapper would be the solution, not a temporary one
I think the reshaping will be done regardless, so making a quick wrapper (for now, before official support) would be sufficient. Something along lines of (not tested, just a sketch):