Skip to content

docs: warn against using Gymnasium FrameStackObservation for image observations#2258

Open
midhunxavier wants to merge 1 commit into
DLR-RM:masterfrom
midhunxavier:docs/framestack-is-image-space-note
Open

docs: warn against using Gymnasium FrameStackObservation for image observations#2258
midhunxavier wants to merge 1 commit into
DLR-RM:masterfrom
midhunxavier:docs/framestack-is-image-space-note

Conversation

@midhunxavier

Copy link
Copy Markdown

Description

Adds a warning to the custom-environment documentation explaining that Gymnasium's FrameStackObservation wrapper adds a new leading dimension to image observations (e.g. an image of shape (3, 64, 64) becomes (2, 3, 64, 64) when stacking 2 frames). SB3's is_image_space check requires exactly 3 dimensions, so the stacked space is treated as a batch of images rather than an image. As a result, a FlattenExtractor is silently used instead of a CNN.

The note recommends using SB3's VecFrameStack instead (which stacks along the channel dimension and keeps the observation recognized as an image) and links to the issue. A changelog entry is added accordingly.

This follows @araffin's guidance in the issue to keep the is_image_space check as-is and document the pitfall instead of changing the behavior.

Motivation and Context

closes #2090

Users stacking image frames with Gymnasium's FrameStackObservation get a silent fallback to FlattenExtractor (no CNN), with no error, which is surprising and hard to debug. Documenting the recommended VecFrameStack alternative prevents this pitfall.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

  • I've read the CONTRIBUTION guide (required)
  • I have updated the changelog accordingly (docs/misc/changelog.md) (required).
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature). — N/A: documentation-only change, no code modified.
  • I have updated the documentation accordingly.
  • I have opened an associated PR on the SB3-Contrib repository (if necessary) — N/A.
  • I have opened an associated PR on the RL-Zoo3 repository (if necessary) — N/A.
  • I have reformatted the code using make format (required) — N/A: no Python code changed (docs only).
  • I have checked the codestyle using make check-codestyle and make lint (required) — N/A: no Python code changed (docs only).
  • I have ensured make pytest and make type both pass. (required) — N/A: no Python code changed (docs only).
  • I have checked that the documentation builds using make doc (required) — build succeeded, no warnings/errors; the warning admonition renders on the custom-env page.

LLM/code-assistant disclosure (per CONTRIBUTING.md): this documentation change was prepared with the assistance of Claude, an LLM code assistant. The approach — documenting the pitfall and recommending VecFrameStack rather than altering is_image_space — was proposed by maintainer @araffin in #2090. I have personally reviewed and verified the change.

…-RM#2090)

Gymnasium's FrameStackObservation adds a leading dimension, turning a
(3, 64, 64) image into (2, 3, 64, 64). SB3's is_image_space() requires
exactly 3 dimensions, so the stacked space is not recognized as an image
and a FlattenExtractor is silently used instead of a CNN.

Per maintainer guidance in DLR-RM#2090, keep the is_image_space check as-is and
document the pitfall instead, recommending VecFrameStack. Adds a warning
admonition on the custom env page and a changelog entry.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant