-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Tiling applied post prediction (in contrast to during loop) #141
Conversation
(Without the unpacking tiles info gets wrapped in a list twice)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #141 +/- ##
==========================================
- Coverage 91.30% 91.23% -0.07%
==========================================
Files 104 103 -1
Lines 2633 2510 -123
==========================================
- Hits 2404 2290 -114
+ Misses 229 220 -9 ☔ View full report in Codecov by Sentry. |
(show failure in #143)
…; since merge happens elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I am wondering a bit what the consequences are for the Lightning API. I guess they just need to call the stitch
method. Since I anyway need to create examples and tests, I will make a PR in that direction as soon as this is merged.
else: | ||
predictions_output = combine_batches(predictions, tiled) | ||
|
||
# TODO: add this in? Returns output with same axes as input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the result of stitch prediction have a "S" dimensions if the input had any? If singleton then I guess it doesn't?
The output should already be shaped correctly. Now what we could do is to reshape back to the real input (which may have the axes in a weird order)... But for now it is better to stick to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see now, this is not the reshape
that we have elsewhere in the code. This is to add S and C back.
If the images are just returned to the user or saved to the disk, we are probably better off not returning singleton dims. It is annoying in terms of coherence, but much nicer for downstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some inconsistencies with output dims depending on whether the prediction was tiled or not. If the prediction was tiled, then because the function stitch_prediction
doesn't expect the S dim, if there was only one image, then the output will also not have an S dim. However, if the prediction is not tiled, then the S dimension is not removed, even if there is only one image.
I have left it like this because I am pretty sure it is recreating how the code was previously behaving, but I can merge this PR and then create a new PR to fix this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make an issue out of it so that we don't loose track of it! Also with respect to the list or not list return value.
I think for now it is ok to merge!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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 inCAREamist.predict
after callingtrainer.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
stitched_prediction
)prediction_utils
package.prediction_outputs
in newprediction_utils
package.Trainer
inCAREamist
no longer has prediction_loop replacedCAREamist.predict
predictions are stitched and/or converted to match oldCAREamistPredictionLoop
outputs.CAREamicsPredictData
has been moved to newprediction_utils
packagestitch_prediction
function has been moved toprediction_utils
packageCAREamistPredictionLoop
stitched_prediction
function.stitched_prediction
tests to match new file structure of src.test_predict_on_array_tiled
andtest_predict_arrays_no_tiling
– parametrised withsamples
andbatch_size
; squeezetrain_array
when asserting size equality.Related Issues
BasePredictionWriter
Callback can be written more easily.Breaking changes
Any code that instantiated a Lightning
Trainer
and added theCAREamistPredictionLoop
.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)
Please ensure your PR meets the following requirements: