-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Tiling applied post prediction (in contrast to during loop) (…
…#141) ### Description Using the regular Lightning prediction loop, and tiled datasets, the tile information is also returned when calling `trainer.predict`. This means there is no reason tiling cannot be applied after prediction instead of during the prediction loop. This means we don't have to write a custom loop, simplifying the code and reducing coupling with Lightning. This will also make life easier when we add saving predictions (tiff or zarr). **What**: Removes `CAREamicsPredictionLoop` (where tiling was previously implemented) and applies tiling in `CAREamist.predict` after calling `trainer.predict` with the regular Lightning prediction loop. **Why**: Altering the Lightning prediction loop was overcomplicated, hard to maintain and made adding an option to save predictions more difficult. **How**: predictions are returned with tiling information so predicted tiles are stitched together at the end of prediction. ### Changes Made - **Added**: - multi-image stitch prediction function (takes name of old stitching function, `stitched_prediction`) - New `prediction_utils` package. - module `prediction_outputs` in new `prediction_utils` package. - **Modified**: - `Trainer` in `CAREamist` no longer has prediction_loop replaced - At the end of `CAREamist.predict` predictions are stitched and/or converted to match old `CAREamistPredictionLoop` outputs. - Creation of `CAREamicsPredictData` has been moved to new `prediction_utils` package - `stitch_prediction` function has been moved to `prediction_utils` package - **Removed**: `CAREamistPredictionLoop` - **Tests** - Added: test for new `stitched_prediction` function. - Added: test for prediction output conversion. - Modified: moved `stitched_prediction` tests to match new file structure of src. - Modified: `test_predict_on_array_tiled` and `test_predict_arrays_no_tiling` – parametrised with `samples` and `batch_size`; squeeze `train_array` when asserting size equality. ### Related Issues - Resolves #140: Now a `BasePredictionWriter` Callback can be written more easily. - Resolves #143: New logic stops tiles from being skipped at the end of batches. ### Breaking changes Any code that instantiated a Lightning `Trainer` and added the `CAREamistPredictionLoop` . There might be some unforeseen changes to dimensions of prediction outputs that the tests do not catch, i.e. adding S & C dims. ### TODO: (for future) - Change prediction so that list is always output (currently, if there is only 1 prediction it will not output a list). - Dimensions of outputs always have all SC(Z)YX, or match input dimensions. Currently, there is some inconsistency between tiled and not tiled prediction output dimensions. **Please ensure your PR meets the following requirements:** - [x] Code builds and passes tests locally, including doctests - [x] New tests have been added (for bug fixes/features) - [x] Pre-commit passes - [ ] PR to the documentation exists (for bug fixes / features) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
37e9ad4
commit 0a29ea2
Showing
19 changed files
with
693 additions
and
411 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Oops, something went wrong.