Skip to content

feat(vit): in-pipeline live orientation auto-detect#45

Merged
Garrett Bischof (gwbischof) merged 1 commit into
mainfrom
h5b/inpipeline-autodetect
Jun 9, 2026
Merged

feat(vit): in-pipeline live orientation auto-detect#45
Garrett Bischof (gwbischof) merged 1 commit into
mainfrom
h5b/inpipeline-autodetect

Conversation

@gwbischof

Copy link
Copy Markdown
Collaborator

H5b of the #37 decomposition — the live in-pipeline orientation auto-detect (final feature PR; H6 is scripts + infra). Builds on the ptychoml pieces merged in #13.

What

On the first batch with ≥64 finite scan positions, PtychoViTInferenceOp runs ptychoml.autodetect_orientation once — a forward-physics sweep of the 8 D4 candidates against the engine's baked probe — and sets ImagePreprocessorOp.dp_orient in place. ImagePreprocessorOp buffers pre-D4 frames for the sweep (_autodetect_buf, capped 256), cleared when done. Engines without a baked probe keep the configured dp_orient (logged, sweep disabled) — so this is a no-op unless the engine was exported with --probe.

Position convention (reproduces #37 — coupled change, confirmed)

This is the half deferred from H4b; columns + ranges must move together:

  • PointProcessorOp default now writes col 0 = slow axis (INENC3/y_range), col 1 = fast (INENC2/x_range) — the hxn_to_vit convention. New position_swap_xy config (default false); true reverts to the legacy fast→col0 assignment (main's old behavior).
  • SaveViTResult canvas ranges swap to match: x_range_um=abs(param.y_range) (slow→width), y_range_um=abs(param.x_range).
  • The sweep feeds autodetect_orientation col 0 = x (fast), so positions are swapped back via ptychoml.remap_positions(swap_xy=True) — verified identical to Enhance image processing and orientation detection in holoptycho #37's inline [[1,0]].

ptychoml reuse

autodetect_orientation + remap_positions are consumed from ptychoml — no algorithm reimplemented. (spatially_diverse_sample from #13 is used by the H5a CLI, not this path — the live buffer uses first-N-buffered frames.)

Testing

This is compose+runtime Holoscan behavior (the ptycho_holo/vit_inference smoke imports already fail on a missing TILED_BASE_URL, before compose), so it's not unit-testable in CI without fighting the infra. Safety net: it faithfully reproduces #37, the reusable bits are ptychoml-tested, the remap_positions(swap_xy=True) substitution is verified bit-identical to #37, and the column/range/swap convention is audited for internal consistency. No regression:

pixi run test   # 90 passed; the 2 vit_inference/ptycho_holo smoke failures are pre-existing.

⚠️ Note: this changes the default mosaic position mapping (col 0 = slow/y) and enables live dp_orient override when the engine has a baked probe — both intentional, matching #37. position_swap_xy=true restores the prior column convention.

On the first batch with >=64 finite scan positions, PtychoViTInferenceOp runs
ptychoml.autodetect_orientation once (forward-physics sweep of the 8 D4
candidates against the engine's baked probe) and sets ImagePreprocessorOp.
dp_orient in place. ImagePreprocessorOp buffers pre-D4 frames for the sweep
(_autodetect_buf, capped 256), cleared when done. Engines without a baked
probe keep the configured dp_orient (logged, sweep disabled).

Position convention (reproduces #37, coupled change):
- PointProcessorOp default now writes col 0 = slow axis (INENC3/y_range),
  col 1 = fast axis (INENC2/x_range) — the hxn_to_vit convention. New
  position_swap_xy config (default false); set true to revert to the legacy
  fast->col0 assignment.
- SaveViTResult canvas ranges swap to match: x_range_um=abs(param.y_range)
  (slow->width), y_range_um=abs(param.x_range). (This is the half deferred
  from H4b; columns + ranges must move together to stay consistent.)
- The sweep feeds autodetect_orientation col 0 = x (fast), so positions are
  swapped back via ptychoml.remap_positions(swap_xy=True) — verified
  identical to #37's inline [[1,0]].

Reuses the merged ptychoml pieces (autodetect_orientation, remap_positions);
no algorithm reimplemented. This is compose+runtime Holoscan behavior
exercised by real runs; the reusable bits are ptychoml-tested and the column/
range/swap convention is audited for consistency. Suite passes (90, modulo the
2 pre-existing TILED smoke imports).

H5b of the #37 decomposition (final feature PR; H6 is scripts
+ infra).

Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.com>
@gwbischof Garrett Bischof (gwbischof) merged commit 4c2c211 into main Jun 9, 2026
5 checks passed
@gwbischof Garrett Bischof (gwbischof) deleted the h5b/inpipeline-autodetect branch June 9, 2026 17:22
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