Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix for the RGBImgPartialObsWrapper view size issue #421

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions minigrid/minigrid_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,19 +649,32 @@ def gen_obs(self):

return obs

def get_pov_render(self, tile_size):
def get_pov_render(self, tile_size, agent_view_size=None):
"""
Render an agent's POV observation for visualization
"""
grid, vis_mask = self.gen_obs_grid()

grid, vis_mask = self.gen_obs_grid(agent_view_size)
'''
Bug Fix for https://github.com/Farama-Foundation/Minigrid/issues/419
- Added the agent_view_size field and used it if provided without
breaking existing code
'''

# Render the whole grid
img = grid.render(
tile_size,
agent_pos=(self.agent_view_size // 2, self.agent_view_size - 1),
agent_dir=3,
highlight_mask=vis_mask,
)
if agent_view_size is None:
img = grid.render(
tile_size,
agent_pos=(self.agent_view_size // 2, self.agent_view_size - 1),
agent_dir=3,
highlight_mask=vis_mask,
)
else:
img = grid.render(
tile_size,
agent_pos=(agent_view_size // 2, agent_view_size - 1),
agent_dir=3,
highlight_mask=vis_mask,
)

return img

Expand Down
13 changes: 12 additions & 1 deletion minigrid/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def __init__(self, env, tile_size=8):
self.tile_size = tile_size

obs_shape = env.observation_space.spaces["image"].shape

new_image_space = spaces.Box(
low=0,
high=255,
Expand All @@ -374,7 +375,17 @@ def __init__(self, env, tile_size=8):
)

def observation(self, obs):
rgb_img_partial = self.get_frame(tile_size=self.tile_size, agent_pov=True)
'''
Bug Fix for https://github.com/Farama-Foundation/Minigrid/issues/419

- Bypass self.get_frame() with self.get_pov_render(). The former method
was not necessary in this context.
- Add an "agent_view_size" field to the self.get_pov_render() method
'''
rgb_img_partial = self.get_pov_render(
tile_size=self.tile_size,
agent_view_size=self.agent_view_size
)

return {**obs, "image": rgb_img_partial}

Expand Down
Loading