feat(preprocess): add inner_crop_from_probe — ViT-patch crop from probe geometry#12
Merged
Merged
Conversation
…be geometry Derive a ViT-patch inner_crop from a reconstruction probe: for a roughly circular probe of radius R (at threshold x peak amplitude), the largest inscribed axis-aligned square gives floor(patch/2 - R/sqrt(2)), clamped to [0, patch//4]. Accepts a complex or real 2-D probe (a model's ONNX-baked probe, or PtychoViTInference.baked_probe). Extracted from the geometry half of holoptycho/vit_inference.py inner_crop_from_onnx so holoptycho can import it (the ONNX-loading / probe extraction glue stays in holoptycho). Note the original docstring formula (patch//2 - floor(R/sqrt2)) didn't match its own code (floor of the whole expression); kept the code's behavior and corrected the formula. Tested in tests/test_preprocess.py: inscribed-square value, quarter-patch clamp, complex-amplitude handling, real==complex, threshold-controls-support, empty->None, 2-D requirement, and a lock against the original geometry on a gaussian probe. Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.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.
Adds
inner_crop_from_probe(probe, threshold=0.5)toptychoml.preprocess.Why
The reconstruction probe's amplitude defines which pixels of each ViT output patch carry meaningful signal. For a roughly circular probe of radius
R(measured atthreshold× peak amplitude), the largest inscribed axis-aligned square gives:Extracted from the geometry half of holoptycho's
inner_crop_from_onnxso holoptycho can import it — the ONNX-loading / probe-tensor extraction glue stays local (filename convention,onnxlib). Accepts a complex or real 2-D probe, so it works on both a model's ONNX-baked probe andPtychoViTInference.baked_probe.Pure numpy, array-in/scalar-out — same boundary as
compute_sample_pixel_size/normalize_mosaic.Note
The original
inner_crop_from_onnxdocstring formula (patch//2 − floor(R/√2)) didn't match its own code (floorof the whole expression — they differ by ±1). I kept the code's behavior (faithful to #37) and corrected the formula in the docstring.Tests
tests/test_preprocess.py(+8): inscribed-square value, quarter-patch clamp, complex-amplitude handling, real==complex, threshold-controls-support, empty→None, 2-D requirement, and a lock against the original geometry on a gaussian probe.First of the two H4 PRs (holoptycho
inner_crop_from_onnxwill call this); the other is true vit-only mode.