neural_tracing: add opt-in displacement scaling across voxel sizes - #1284
Open
Nieuwlaar wants to merge 2 commits into
Open
neural_tracing: add opt-in displacement scaling across voxel sizes#1284Nieuwlaar wants to merge 2 commits into
Nieuwlaar wants to merge 2 commits into
Conversation
…crollPrize#1149) @LimeGS reports in ScrollPrize#1149 that copy_displacement_latest (trained at 4.8 um) predicts offsets in training-resolution voxels, and that inference applies them directly regardless of the target volume's voxel size. On one 7.91 um Scroll 3 window a post-hoc 4.8/7.91 scale reduced wrong-hop rates from 63.17% to 5.90% (front, n=4,697) and 56.28% to 7.73% (back, n=8,697). He notes that this is a local geometric benchmark, not ground truth, and that it does not establish that automatic scaling is universally correct. The issue asks for an opt-in flag defaulting to 1.0, checkpoint metadata, and a mismatch warning, and explicitly asks that automatic scaling not be enabled by default before the unit contract is settled. This implements that shape: - --displacement-scale accepts a positive number, or "auto" to derive training_voxel_size_um / inference voxel size from the checkpoint config. Also exposed as a trace-service copy arg via _COPY_ARG_TO_CLI. - Without the flag, displacements are applied unscaled exactly as before. A warning fires only when the checkpoint advertises a training voxel size that differs from the inference one, so a real mismatch is not silent and no geometry changes without an explicit request. - The inference voxel size is the volume meta.json voxelsize (or --tifxyz-voxel-size-um) times 2**volume_scale. - displacement_scale and its source are recorded in run and tifxyz metadata. - Unit tests cover the unscaled default, the mismatch warning, "auto" derivation and its failure modes, explicit overrides, and invalid input. Refs ScrollPrize#1149.
|
@nieuwlaar42 is attempting to deploy a commit to the scroll Team on Vercel. A member of the Team first needs to authorize it. |
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.
neural_tracing: add opt-in displacement scaling across voxel sizes
Refs #1149.
This implements the three changes @LimeGS proposed in #1149. The analysis, the benchmark, and the interface are theirs; I wrote the patch because the issue has had no maintainer reply in sixteen days and I wanted the option available. Happy to close this in favour of their own PR, or to co-author, whichever they prefer.
Background
Per #1149,
copy_displacement_latestwas trained at 4.8 µm, andinfer_rowcol_triplet_wraps.pyapplies predicted displacement vectors directly (world + slot_*_disp) with no resolution conversion. On one 7.91 µm Scroll 3 window, a post-hoc4.8 / 7.91 = 0.6068scale changed wrong-hop rates from 63.17% to 5.90% (front, n=4,697) and 56.28% to 7.73% (back, n=8,697).@LimeGS is explicit that this is a local geometric benchmark rather than ground truth: it shows a magnitude-calibration problem in that window, and does not establish that automatic
4.8 / input_pitchscaling is universally correct. The underlying question in the issue, what the intended output-unit contract is for non-4.8 µm inputs, is still unanswered, so nothing here changes behaviour unless you ask it to.What this adds
--displacement-scale, accepting either a positive number orauto:It is also exposed as a trace-service copy arg through
_COPY_ARG_TO_CLI.Default behaviour is unchanged. With no flag, displacements are applied unscaled exactly as before. This deliberately follows the issue's request to keep scaling opt-in and not enable automatic scaling before the semantics are confirmed.
A warning, but only for a genuine mismatch. When the checkpoint config carries
training_voxel_size_umand it differs from the inference voxel size, a warning names both values and suggests the flag. Checkpoints without that key stay completely silent, so nobody gets new noise for an unchanged setup. No published checkpoint carries the key today, so in practice this is inert until someone adds it.Provenance.
displacement_scaleanddisplacement_scale_source(cli,auto, ordefault) are recorded in the run and tifxyz metadata, so a rendered surface says which scale produced it.Implementation notes
The scale multiplies the six displacement channels once, immediately after prediction and before accumulation, in
_run_triplet_inference. Side assignment uses the sign of displacement dotted with the normal, which is invariant under positive scaling, so it is unaffected.The inference voxel size is the volume's
meta.jsonvoxelsize(or--tifxyz-voxel-size-um) multiplied by2**volume_scale, reusing the sameretarget_factoralready used to retarget the surface grid. The unrelated 8.24 µm fallback inresolve_tifxyz_paramsis deliberately not used for scaling: guessing a voxel size and silently rescaling geometry from it would be worse than doing nothing.Tests
vesuvius/tests/neural_tracing/test_displacement_scale.pycovers the unscaled default (silent, and with the mismatch warning),autoderivation and each of its failure modes, explicit overrides including disagreement with checkpoint metadata, invalid inputs, and theautopredicate itself.Open question for maintainers
The issue's actual question still stands: should displacements on non-4.8 µm volumes be interpreted in training-grid or inference-grid voxels? If the answer is training-grid, then
autois arguably the right default and I am happy to flip it. This PR does not presume that answer.