-
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.
Fix: Inconsistent prediction outputs (#170)
### Description Prediction outputs were inconsistent. Firstly, if there was only 1 sample the output would not be a list. Secondly, and less predictably, if the prediction was tiled, then singleton channel dimensions would be dropped. This PR makes sure that the output of `CAREamist.predict` is always a list and that the outputs always have the same dimensions. **What**: - The `stitched_prediction` function will now output arrays with dimensions `SC(Z)YX` where S will always be singleton. - Tests have been updated to always expect lists from `CAREamist.predict`. Additionally, instead of squeezing prediction outputs, the input arrays are reshaped when comparing dimensions; this should make the tests a little more robust. **Why**: - Having `stitched_prediction` output `SC(Z)YX` arrays simplifies the `prediction_utils.convert_outputs` function, in which, if a prediction has 3 dimensions it can be ambiguous whether the first dimension is Z or C. If the first dimension is Z then we need to add both the S & C singleton dims, and if the first dimension is C then we only need to add the S singleton dimension. **How**: - Solved not very elegantly by expanding the `predicted_image` dimensions, based on the first tile's dimensions, in `stitch_prediction_single`. - This can be solved more elegantly by allowing `TileInformation.array_shape` to have singleton dimensions. ### Changes Made **Modified**: - `careamics.prediction_utils.convert_outputs` - `careamics.prediction_utils.stitch_prediction_single` - `CAREamsit.export_to_bmz` - tests ### Related Issues - Fixes #156 - `stitch_prediction_single` now accepts inputs with dimensions `SC(Z)YX`. There was an incorrect assumption that C was the first axis before this PR. ### Breaking changes Code working with prediction outputs. ### Additional Notes and Examples Related to allowing `TileInformation.array_shape` to have singleton dimensions, in my opinion, after data is initially input and reshaped, we should always assume all internal code is working with data in the form SC(Z)YX. This will reduce some ambiguity and confusion. The prediction output dimensions could be changed to C(Z)YZ as I initially suggested in #156, since S is always 1. This would mean replacing `np.concatenate` with `np.stack` in a lot of places that combine prediction samples. --- **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)
- Loading branch information
1 parent
da187e7
commit f223aa7
Showing
8 changed files
with
72 additions
and
94 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 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 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