-
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
Refactoring: Decouple tiling from prediction loop #140
Comments
I am now leaning towards having stitching applied after prediction, which means we don't have to mess around with the lightning implementation too much and don't have to do the hacky Then we can write a I feel this will remove some complication in the code. |
First off, totally agree!! We need something easier to maintain and with a more straightforward data flow.
What bothers me with the CallBack is that they are instantiated with the trainer. Which means that the prediction writer needs to handle all these cases:
Either the callback can easily handle all that, or we need separate CallBacks and a possibility to switch between them depending on the user call (
Is this the solution you are exploring in #141 ?
I like the predictions stitching after trainer.predict, but that's not compatible with writing to disk, isn't it? As for the people using the I might be arriving after the fight here (sorry for the delay), if I understand correctly:
|
They actually are compatible!
|
Great, thanks for the summary! Just to clarify after the discussion here: since the Does lightning have mechanism to disable callbacks after instantiation? Or to update them? |
No, annoyingly 😔
Following that discussion, if |
Description
I think the tiling logic should probably be removed from the prediction loop.
Why
run
function is copied from the original Lightning_PredictionLoop
class with the tiling logic added in-between the Lightning code. This is hard to maintain if Lightning ever change their code.CAREamicsPredictionLoop
is incompatible withtrainer.predict(*args, **kwargs, return_predictions=False)
.Two solutions
Tiling as a Callback
Lightning already has a
BasePredictionWriter
Callback. There is awrite_on_batch_end
hook that could handle writing to zarr files or caching tiles until the last tile to save to tiff. The outputs oftrainer.predict
can also be changed so that it is the full prediction and not the tiles. I have implemented a version of this as a demo in this branch, where I move the current tiling logic to a callback. (This would have to change a lot to accommodate writing predictions).Tiling in
CAREamicsModule
I don't like this option as much because it doesn't feel like what the
LightingModules
are for.LightningModule
s have all the same hooks asCallback
,on_predict_batch_end
etc. So all the tiling logic could move there.Discusion points
Please comment likes/dislikes with either solution or a new solution and any other thoughts!
Does
trainer.predict
have to output the stitched predictions?trainer.predict
, inon_predict_epoch_end
we have to do:CAREamist
class never need to see this (happens inCAREamist.predict
). Users not using theCAREamist
class have more control, which is why they might not be using it.Something to consider:
CAREamist
class, if they want tiled predictions, currently have to do:PredictionWriterCallback
for saving tiles.The text was updated successfully, but these errors were encountered: