docs: warn against using Gymnasium FrameStackObservation for image observations#2258
Open
midhunxavier wants to merge 1 commit into
Open
docs: warn against using Gymnasium FrameStackObservation for image observations#2258midhunxavier wants to merge 1 commit into
midhunxavier wants to merge 1 commit into
Conversation
…-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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a warning to the custom-environment documentation explaining that Gymnasium's
FrameStackObservationwrapper 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'sis_image_spacecheck requires exactly 3 dimensions, so the stacked space is treated as a batch of images rather than an image. As a result, aFlattenExtractoris silently used instead of a CNN.The note recommends using SB3's
VecFrameStackinstead (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_spacecheck as-is and document the pitfall instead of changing the behavior.Motivation and Context
closes #2090Users stacking image frames with Gymnasium's
FrameStackObservationget a silent fallback toFlattenExtractor(no CNN), with no error, which is surprising and hard to debug. Documenting the recommendedVecFrameStackalternative prevents this pitfall.is_image_spaceworks poorly with Gymnasium'sFrameStackObservation#2090, triaged by a maintainer (@araffin), who proposed this documentation approach.Types of changes
Checklist
docs/misc/changelog.md) (required).make format(required) — N/A: no Python code changed (docs only).make check-codestyleandmake lint(required) — N/A: no Python code changed (docs only).make pytestandmake typeboth pass. (required) — N/A: no Python code changed (docs only).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
VecFrameStackrather than alteringis_image_space— was proposed by maintainer @araffin in #2090. I have personally reviewed and verified the change.