Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates spectre.io resampling to be compatible with newer MONAI behavior (affine carried on a MetaTensor rather than passed to Spacing) and adds tests to prevent regressions in both CT resampling and the HuggingFace transformers wrapper.
Changes:
- Fix
resample()to pass affine viamonai.data.MetaTensorinstead of the removedSpacing(..., affine=...)argument. - Add end-to-end tests for NIfTI load/resample and the
load_and_window(..., spacing=...)path. - Add tests covering the
transformerswrapper call contract (ignored kwargs, refused output flags, return types).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/spectre/io.py |
Updates resampling implementation to use MetaTensor affine propagation for MONAI compatibility. |
tests/test_io_resample.py |
Adds regression + integration tests for CT load/window/resample behavior. |
tests/test_hf_modeling.py |
Adds tests for the HuggingFace wrapper’s forward contract and error handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+164
to
168
| volume = MetaTensor(x, affine=torch.as_tensor(meta.affine, dtype=torch.float64)) | ||
| spacer = Spacing(pixdim=tuple(float(s) for s in spacing), mode=mode) | ||
| resampled = spacer(x, affine=torch.as_tensor(meta.affine, dtype=torch.float64)) | ||
| resampled = spacer(volume) | ||
| affine = getattr(resampled, "affine", meta.affine) | ||
| resampled = resampled.as_tensor() if hasattr(resampled, "as_tensor") else torch.as_tensor(resampled) |
Comment on lines
+43
to
+45
| assert new_meta.spacing == (0.5, 0.5, 1.0) | ||
| # Finer spacing on two axes -> more voxels; coarser depth spacing (1.0 < 1.5) -> more too. | ||
| assert resampled.shape[1] > volume.shape[1] |
Comment on lines
+26
to
+30
| spec = importlib.util.spec_from_file_location(name, ROOT / "hf_export" / f"{name}.py") | ||
| module = importlib.util.module_from_spec(spec) | ||
| sys.modules[name] = module | ||
| spec.loader.exec_module(module) | ||
| return module |
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.
This pull request improves the resampling logic in
spectre.ioto correctly handle changes in the MONAI library and adds comprehensive tests to cover resampling and the HuggingFacetransformersintegration. The main focus is on fixing a regression where an outdated argument was passed toSpacing, ensuring correct affine handling, and adding tests to prevent future regressions.Resampling logic fixes and improvements:
resamplefunction insrc/spectre/io.pyto useMetaTensorfor passing affine information, as the latest MONAI expects affine data on the tensor rather than as a function argument. This fixes a TypeError caused by passing an unsupportedaffineargument toSpacing. [1] [2]Test coverage:
tests/test_io_resample.pyto provide thorough coverage of CT scan resampling, including shape/spacing checks, error handling, and integration with windowing and cropping. This ensures the resampling path is robust and correct, especially after the recent API change in MONAI.tests/test_hf_modeling.pyto test the HuggingFacetransformerswrapper around theSpectreImageFeatureExtractor, verifying call contracts, output types, error handling for unsupported kwargs, and the correct exposure of model attributes.