Skip to content

Adds support for varying resolution to shadow hand vision task - #4866

Merged
ooctipus merged 3 commits into
isaac-sim:developfrom
kellyguo11:sh-vision-resolution
Mar 7, 2026
Merged

ooctipus merged 3 commits into
isaac-sim:developfrom
kellyguo11:sh-vision-resolution

Conversation

@kellyguo11

Copy link
Copy Markdown
Contributor

Description

The shadow hand vision task had been using a fixed camera resolution.

For benchmarking purposes, we want to run the environment at different resolutions. Adding support to the Feature Extractor to allow for arbitrary input resolution.

Also fixes an issue with Newton inertia shape.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@kellyguo11
kellyguo11 requested a review from ooctipus as a code owner March 7, 2026 02:18
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Mar 7, 2026
@greptile-apps

greptile-apps Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes the Shadow Hand vision task's FeatureExtractor CNN resolution-independent for benchmarking purposes, and bundles two unrelated Newton physics bug fixes. The changes are generally clean and well-documented.

Key changes:

  • Variable-resolution CNN (feature_extractor.py, shadow_hand_vision_env.py): FeatureExtractorNetwork now accepts height and width parameters and uses a helper _conv_out to derive LayerNorm spatial dimensions dynamically. AvgPool2d(6) is replaced with AdaptiveAvgPool2d(1), making the CNN robust to any input resolution at or above the minimum dictated by the conv stack (~40 px). The env correctly passes cfg.tiled_camera.height/width through to the network.
  • Newton inertia shape fix (articulation_data.py): Reinterprets the (N, B, 3, 3) warp array returned by Newton as a (N, B, 9) view using explicit byte strides and copy=False, matching the documented contract and the expected input shape of the downstream kernels. The fix relies on a contiguity assumption that is documented in comments but not asserted.
  • Newton CUDA-graph guard fix (newton_manager.py): Replaces a three-condition heuristic (cfg is not None and cfg.use_cuda_graph and "cuda" in device) with a direct cls._graph is not None check, eliminating an AttributeError that surfaced when use_cuda_graph=True but graph capture did not run.
  • Benchmark script updates (benchmark_rsl_rl.py): Adds a deprecated-config migration shim (handle_deprecated_rsl_rl_cfg) and renames the "Perf/collection time" log key to "Perf/collection_time" to track an upstream rsl-rl key rename.

Confidence Score: 4/5

  • PR is safe to merge; all changes are well-motivated bug fixes or additive features with no breaking API changes.
  • The CNN resolution change is correct and backwards-compatible (defaults preserved). The Newton fixes address real bugs with appropriate fallback paths. Minor style concerns: the conv-output helper lacks a minimum-resolution guard, and the stride-collapse assumes memory contiguity without an assertion.
  • source/isaaclab_tasks/isaaclab_tasks/direct/shadow_hand/feature_extractor.py (missing resolution guard), source/isaaclab_newton/isaaclab_newton/assets/articulation/articulation_data.py (unasserted contiguity assumption in stride manipulation)

Important Files Changed

Filename Overview
source/isaaclab_tasks/isaaclab_tasks/direct/shadow_hand/feature_extractor.py Adds height/width parameters to FeatureExtractorNetwork and FeatureExtractor, replaces fixed LayerNorm shapes with dynamically-computed sizes, and replaces the hard-coded AvgPool2d(6) with AdaptiveAvgPool2d(1). Logic is sound but there is no guard against resolutions too small for the conv stack.
source/isaaclab_tasks/isaaclab_tasks/direct/shadow_hand/shadow_hand_vision_env.py Correctly threads height and width from the tiled camera config into FeatureExtractor. No issues found.
source/isaaclab_newton/isaaclab_newton/assets/articulation/articulation_data.py Fixes body_inertia shape from (N, B, 3, 3) to (N, B, 9) via zero-copy stride manipulation. Correct for contiguous arrays but relies on an unasserted memory-layout assumption.
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Simplifies CUDA graph launch condition from a three-way heuristic check to a direct None-check on cls._graph, fixing the AttributeError when the graph was not captured. Clean and correct.
scripts/benchmarks/benchmark_rsl_rl.py Adds handle_deprecated_rsl_rl_cfg shim for rsl-rl-lib compatibility and renames "Perf/collection time" key to "Perf/collection_time" to match upstream rsl-rl log key rename. No issues found.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ShadowHandVisionEnv.__init__] --> B["Read cfg.tiled_camera.height / width"]
    B --> C["FeatureExtractor.__init__(height, width)"]
    C --> D["FeatureExtractorNetwork.__init__(height, width)"]
    D --> E["_conv_out × 4 layers\n(h1,w1) → (h2,w2) → (h3,w3) → (h4,w4)"]
    E --> F["LayerNorm([16, h1, w1])\nLayerNorm([32, h2, w2])\nLayerNorm([64, h3, w3])\nLayerNorm([128, h4, w4])"]
    F --> G["AdaptiveAvgPool2d(1)\n→ always (N,128,1,1)"]
    G --> H["Linear(128, 27)\n→ keypoint embedding"]

    I[ArticulationData._initialize_sim_data] --> J["get_attribute body_inertia\n→ raw (N, B, 3, 3) warp array"]
    J --> K{"ndim == 4?"}
    K -- yes --> L["wp.array(ptr, shape=(N,B,9),\nstrides=(s0,s1,s3), copy=False)"]
    K -- no --> M["use array as-is"]

    N[NewtonManager.step] --> O{"cls._graph is not None?"}
    O -- yes --> P["wp.capture_launch(cls._graph)"]
    O -- no --> Q["wp.ScopedDevice → cls._simulate()"]
Loading

Last reviewed commit: 46d2c35

Comment on lines +40 to +42
def _conv_out(size: int, kernel: int, stride: int, padding: int = 0) -> int:
"""Compute the spatial output size of a single convolutional layer."""
return (size + 2 * padding - kernel) // stride + 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No minimum resolution validation

_conv_out uses floor division and can return 0 or negative values for very small inputs (e.g., _conv_out(5, 6, 2) → (5 - 6) // 2 + 1 = 0). With four stacked convolutions (kernels 6, 4, 4, 3), the minimum valid side is ~40 px. If a user passes a smaller resolution the error surfaces inside nn.LayerNorm construction with an opaque PyTorch message rather than a clear user-facing one.

Consider adding an early check in FeatureExtractorNetwork.__init__:

if h4 <= 0 or w4 <= 0:
    raise ValueError(
        f"Image resolution {height}x{width} is too small for the CNN architecture "
        f"(requires at least ~40x40). Got spatial sizes after all conv layers: "
        f"h4={h4}, w4={w4}."
    )

@ooctipus
ooctipus merged commit 1297dbf into isaac-sim:develop Mar 7, 2026
6 of 9 checks passed
@ooctipus
ooctipus deleted the sh-vision-resolution branch March 7, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants