Skip to content

Turn a calibrated GenSim object to the heading its mask shows - #1336

Open
Yuan-Xinyi wants to merge 1 commit into
mainfrom
fix/gensim-calibration-orientation
Open

Yuan-Xinyi wants to merge 1 commit into
mainfrom
fix/gensim-calibration-orientation

Conversation

@Yuan-Xinyi

Copy link
Copy Markdown
Collaborator

Description

GenSim source calibration could give a tabletop object an arbitrary size when the generated scene had the object at the wrong heading. This PR turns such an object about the vertical to the heading its image mask shows, and flags the objects no heading can match. Objects that already match are untouched.

Related to #1248 (B1, "Object yaw is not reproduced"). The wrong heading itself comes from scene generation and is not addressed here; this PR stops the calibration step from turning a wrong heading into a wrong size as well.

The problem

handover_mic: the source frame shows a microphone lying on the table, pointing away from the camera.

Source frame of handover_mic

  • The generated asset has the right size: 19.4 cm long, 6.4 cm across.
  • The generated scene places it lying across the view, about 90° off.
  • After calibration it enters the simulation at 0.44 scale: 8.7 cm long, while every other object of these scenes is scaled by about 0.75.
  • reference_layout.json recorded relative_extent_error: 0.83 for it. Nothing acted on that number.

Cause

_fit_object fits one uniform scale and a tabletop position so that the projected bounding box matches the mask's bounding box, with the mesh fixed at its generated heading. The mask of the microphone is 48 × 144 px (narrow and tall). Lying across the view, the mesh projects wide and short, so no scale can match both sides; least squares returns a compromise. calibrate_scene applies that scale whatever the residual is.

Change

  • The generated heading is kept while its fit reproduces the mask's bounding box within 10% of the mask's width and height.
  • Otherwise the object is fitted at every heading on a 5° grid about the vertical. Among the headings that do reproduce the box, the one whose projected convex outline overlaps the mask most (IoU) is taken. The bounding box alone cannot tell a heading from its half turn; the outline can for an asymmetric object.
  • An object that no heading matches keeps its generated heading and fit, as before, and now raises a RuntimeWarning.
  • reference_layout.json gains heading_offset_deg and matches_mask per object.

Measured before and after

The calibration was recomputed offline for the 87 tabletop rigid objects of 50 scenes generated from RoboTwin first frames (existing scene exports and masks; no scene was regenerated).

  • 13 objects are turned. Their bounding-box error falls from 12–83% to 0–9%.
  • 74 objects are unchanged, bit-identical in scale.
  • 2 objects match at no heading and are now flagged: the hammer of beat_block_hammer (91%) and the bottle of shake_bottle (21%). Why they do not match was not investigated.

Green is the object's mask in the source frame; orange and blue are the projected outline of the calibrated object before and after.

Projected objects before and after

Bounding-box error before and after

Object Box error Mask overlap (IoU) Scale Longest side Turned
handover_mic / mic 83% → 2% 0.10 → 0.78 0.44 → 0.75 8.7 → 14.8 cm 85°
move_stapler_pad / black_pad 71% → 3% 0.36 → 0.95 0.77 → 0.85 10.2 → 11.2 cm 270°
move_stapler_pad / stapler 64% → 6% 0.36 → 0.87 0.78 → 0.81 9.2 → 9.7 cm 75°
grab_roller / rolling_pin 55% → 5% 0.30 → 0.86 0.78 → 0.77 24.6 → 24.0 cm 15°
scan_object / scanner 35% → 3% 0.51 → 0.74 0.71 → 0.64 16.1 → 14.7 cm 20°
move_playingcard_away / box 25% → 0% 0.55 → 0.96 0.78 → 0.75 10.8 → 10.6 cm 265°

Not covered

  • A heading that is wrong but still reproduces the bounding box within 10% is kept, for example the rotated cubes of [Bug Report] GenSim scene understanding and scene generation problems on RoboTwin first frames #1248 B1.
  • An object generated in the wrong resting pose (standing instead of lying) cannot be fixed by a turn about the vertical; it is only flagged.
  • The end-to-end runs were not repeated with this change: the GPU host was unavailable. Whether the tasks using these objects now succeed is untested.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

See "Measured before and after" above.

Validation

  • pytest tests/gen_sim/test_source_calibration.py: 8 passed. Two cases are new: an object generated across the view and photographed along it is turned and keeps the scene's scale; an object generated standing and photographed lying is flagged and warned about. The six existing cases cover the unchanged path.
  • black --check on the changed files.
  • tests/gen_sim/test_workflow.py has 38 failures in my local environment with and without this change (a robot-registry mapping of the local install); none involve this module.

Checklist

  • I have run the black . command to format the code base.
  • I reviewed affected documentation and agent context, updated it where needed, or explained why no update was needed. (embodichain/gen_sim/README.md describes the new behaviour; the gen-sim agent context only names the option and needs no change.)
  • Public API changes are reflected in the API docs (python docs/scripts/check_api_docs.py), if applicable (no public API changes; the module exports nothing).
  • I verified appropriate behavioral coverage, reviewed the necessity of added or extended tests, and explained when no new tests were needed.
  • Dependencies have been updated, if applicable (none).

🤖 Generated with Claude Code

Source calibration fitted a uniform scale and tabletop position at the
generated heading only. When that heading is wrong the object's projection
cannot take the shape of its mask, and the least-squares scale is an
arbitrary compromise: a microphone generated across the view but
photographed pointing away from the camera came out at 0.44 scale.

An object whose bounding box cannot be matched within 10% at the generated
heading is now turned about the vertical to the heading whose projected
outline overlaps the mask most. Objects that already match are unchanged.
One that no heading matches keeps its generated heading, is flagged in
reference_layout.json and raises a warning.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@Yuan-Xinyi Yuan-Xinyi added bug Incorrect existing behavior or a fix restoring the intended behavior. gen-sim Scene Engine generation and editing, scene export and SimReady pipelines. labels Dec 4, 2026
@greptile-apps

greptile-apps Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The change affects scene setup only when source calibration is used.

The PR appears safe to merge, with a non-blocking gap in tests for asymmetric objects.

FindingsFix All in Codex

  1. P2 Opposite headings remain unchecked ▶
Fix with agent prompt
### Issue 1
tests/gen_sim/test_source_calibration.py:178
This test uses a box and accepts either 90° or 270°, so it cannot check whether `_mask_overlap` selects the right half turn. A change that reverses asymmetric objects could still pass. Add an asymmetric mesh whose competing headings both pass the box check, then assert that the heading with better overlap wins.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR adds a heading search when a generated object's fitted box differs from its mask by more than 10%.

  • Source calibration turns objects whose generated heading misses the image mask.

Intentional limits acknowledged by Yuan-Xinyi: headings that already pass the box check stay unchanged, and wrong resting poses are only flagged because vertical turns cannot fix them.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Fit generated heading] --> B{Box error within 10%?}
  B -->|Yes| C[Keep generated heading]
  B -->|No| D[Fit headings every 5 degrees]
  D --> E{Any heading matches?}
  E -->|Yes| F[Choose greatest mask overlap]
  E -->|No| G[Keep generated fit and warn]
  C --> H[Save pose, scale and report]
  F --> H
  G --> H
Loading

Reviews (1) · Last reviewed commit: "fix(gensim): turn a calibrated object to..." · Reviewed by Greptile

(fit,) = report["objects"]
# Without the turn the wide box is squeezed into the tall mask at a
# fraction of its size; turned, it keeps the scene's one-third scale.
assert fit["heading_offset_deg"] in (90.0, 270.0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Opposite headings remain unchecked

This test uses a box and accepts either 90° or 270°, so it cannot check whether _mask_overlap selects the right half turn. A change that reverses asymmetric objects could still pass. Add an asymmetric mesh whose competing headings both pass the box check, then assert that the heading with better overlap wins.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/gen_sim/test_source_calibration.py
Line: 178

Comment:
**Opposite headings remain unchecked**

This test uses a box and accepts either 90° or 270°, so it cannot check whether `_mask_overlap` selects the right half turn. A change that reverses asymmetric objects could still pass. Add an asymmetric mesh whose competing headings both pass the box check, then assert that the heading with better overlap wins.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex Fix in Claude Code

@Yuan-Xinyi
Yuan-Xinyi requested a review from yuecideng December 4, 2026 08:32
@yuecideng
yuecideng requested a review from MuziWong December 4, 2026 08:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Incorrect existing behavior or a fix restoring the intended behavior. gen-sim Scene Engine generation and editing, scene export and SimReady pipelines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant