-
Notifications
You must be signed in to change notification settings - Fork 638
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
Add ensembling methods for tiling to Anomalib #1226
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: Blaz Rolih <blaz.rolih@gmail.com>
Signed-off-by: Blaz Rolih <blaz.rolih@gmail.com>
Signed-off-by: Blaz Rolih <blaz.rolih@gmail.com>
Signed-off-by: Blaz Rolih <blaz.rolih@gmail.com>
Signed-off-by: Blaz Rolih <blaz.rolih@gmail.com>
Signed-off-by: Blaz Rolih <blaz.rolih@gmail.com>
Signed-off-by: Blaz Rolih <blaz.rolih@gmail.com>
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.
Thanks! Massive efforts here. I have a few minor comments regarding refactoring the config file. It is more of a personal preference. Other than that, I think there are some files that might be left over from the previous version.
out = {} | ||
for step in tqdm(self.steps): | ||
if step.final_compute: | ||
out[step.name] = step.compute() |
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.
From what I understand, compute
is only defined for EnsembleMetrics
, and is the only one for which final_compute
is set to True
. I have two ideas here but they are more of a personal preference,
- Remove
final_compute
and implementcompute
for all sub-classes withpass
or - Use
is_overridden
fromlightning_utilities.core.overrides
to explicitly check if the step hascompute
defined
something likeif is_overridden("compute", step): step.compute()
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.
This is no longer used, I'll delete these files asap.
tiler (EnsembleTiler): Tiler object used to get tile dimension data. | ||
""" | ||
|
||
name = "pipeline" |
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.
How about we rename this to SmoothSeams
?
) | ||
runners.append(SerialRunner(MergeJobGenerator())) | ||
|
||
if args["pipeline"]["ensemble"]["post_processing"]["seam_smoothing"]["apply"]: |
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.
Since each job is supposed to be independent, how about we move this to a separate section in the config.
Instead of defining the entire config under pipeline we can move each config under its separate key. So, if we set the SmoothingJob.name
parameter to SmoothSeams
or something, we can then move seam_smoothing
section under post_processing
to SmoothSeams
.
TrainModel:
...
Predict:
...
SmoothSeams:
apply: True
sigma: 2
width: 0.1
ComputeStatistics:
...
Then we can just check if args['SmoothSeams']['apply']:
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.
The solution above should work for this case and is much nicer than what I have now.
The problem here is that some pipeline stages require args from some other part of config. For example, model training job needs to know normalization stage to determine if normalization should be applied at tile level, but normalization stage is is part of post processing. Since the pipeline class does this _args = args.get(runner.generator.job_class.name, None)
it would then mean that train job doesn't have access, or I'd need to duplicate this.
So I'm not sure how to best handle such cases with current design.
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.
One possibility is to somehow accumulate the ones that are shared under one name, but then the config file looses the structure a bit.
# tiler is used to determine where seams appear | ||
tiler = get_ensemble_tiler(args) | ||
yield SmoothingJob( | ||
accelerator=args["accelerator"], |
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.
How about we pass accelerator
in the init
method? This way, the only arguments this method relies are under the seam_smoothing
method.
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.
That could work yeah. Seam smoothing actually relies only on the params under seam_smoothing.
accelerator=args["accelerator"], | ||
predictions=prev_stage_result, | ||
width_factor=args["ensemble"]["post_processing"]["seam_smoothing"]["width"], | ||
filter_sigma=args["ensemble"]["post_processing"]["seam_smoothing"]["width"], |
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.
Is this supposed to be sigma
?
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.
Yes, thanks.
@@ -0,0 +1,107 @@ | |||
"""Fixtures that are used in tiled ensemble testing""" | |||
|
|||
# Copyright (C) 2023 Intel Corporation |
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.
# Copyright (C) 2023 Intel Corporation | |
# Copyright (C) 2024 Intel Corporation |
from pytorch_lightning.callbacks import ModelCheckpoint | ||
from tools.tiled_ensemble.ensemble_tiler import EnsembleTiler | ||
from tools.tiled_ensemble.post_processing.postprocess import NormalizationStage | ||
from tools.tiled_ensemble.predictions import ( |
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.
Is this up-to-date?
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.
These are old files, will be removed.
@@ -0,0 +1,112 @@ | |||
"""Tiler used with ensemble of models.""" |
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.
Do we need this here now that is moved to src/anomalib
?
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.
No, I'll delete this.
@@ -0,0 +1,124 @@ | |||
"""Anomalib Testing Script for ensemble of models. |
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 guess this needs to be updated as well.
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'll go over the test and rewrite them after I refactor the other things that you pointed out.
@@ -0,0 +1,33 @@ | |||
""" |
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 am confused about this. Is this still relevant?
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.
No it's not, I'll remove this.
Okay. I'll check those out, thanks for going over the code. Indeed there are still some files left over as the refactor is still not 100% done therefore I left it as draft PR). I still need to cover the tests and all so I didn't delete everything. |
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
Signed-off-by: blaz-r <blaz.rolih@gmail.com>
I answered to some comments, and will refactor the config as you suggested in on of the comments. After the refactors I'll also update/rewrite all the tests. Thanks for all the feedback and patience, I'm quite busy right now and I'll really try to get this sorted when I get some time here and there. |
Description
This PR adds mechanism to train ensemble of models on tiled images. It is part of Google Summer of Code.
A lot of details on implementation as well as discussion can be accessed in #1131.
Closes #1727
Changes
Checklist
Some things still todo (tests, docs...) but most of the code is ready for review.