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
π Allow passing model to engine constructor #1780
base: main
Are you sure you want to change the base?
π Allow passing model to engine constructor #1780
Conversation
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
β¦-to-engine-constructor
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Hi @samet-akcay. Could you please run the unit tests? If all goes well, I will update the codebase and documentation to use the new API in a few days. |
@danylo-boiko the tests are triggered only for non-draft PRs. You can either mark this as ready for review or run the tests locally |
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Check out this pull request onΒ See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Signed-off-by: Danylo Boiko <danielboyko02@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 for the efforts!
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
README.md
Outdated
datamodule = MVTec() | ||
model = Patchcore() | ||
engine = Engine() | ||
engine = Engine(model=Patchcore()) |
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 this change should not change the default behaviour, so this document could stay as is. If we want to mention this feature, this could be an additional example.
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 for creating this PR. I've got some comments, but would also like to hear @djdameln's opinions.
@@ -103,10 +103,10 @@ from anomalib.engine import Engine | |||
datamodule = MVTec(num_workers=0) | |||
# Specify backbone and layers | |||
model = Padim(backbone="resnet18", layers=["layer1", "layer2"]) | |||
engine = Engine(image_metrics=["AUROC"], pixel_metrics=["AUROC"]) | |||
engine = Engine(model=model, image_metrics=["AUROC"], pixel_metrics=["AUROC"]) |
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.
Same here, I think. The default behaviour should stay the same.
@@ -155,8 +156,12 @@ def __init__( | |||
if self.task == TaskType.SEGMENTATION: | |||
self.pixel_metric_names = pixel_metrics if pixel_metrics is not None else ["AUROC", "F1Score"] | |||
|
|||
self._model: AnomalyModule | None = None |
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.
What is the difference between self.model
and self._model
?
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.
self._model
is a field. I created a getter/setter self.model
to move the self._setup_trainer(model)
call to the setter and keep the logic simpler.
@@ -495,24 +511,33 @@ def fit( | |||
anomalib fit --config <config_file_path> | |||
``` | |||
""" | |||
if model: | |||
self.model = model | |||
elif not self.model: |
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.
elif not self.model: | |
if not self.model: |
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.
Why do we need this double check?
src/anomalib/engine/engine.py
Outdated
>>> engine = Engine(model=model) | ||
>>> engine.fit(datamodule=datamodule) | ||
>>> engine.test(datamodule=datamodule) |
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.
Same as above, this should not change the default behaviour. We could provide an additional example, showing this new feature.
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Thank you for your feedback, I have made the necessary changes. |
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
@samet-akcay, could you please take a look at the changes/comments when you have some free time? |
π Description
β¨ Changes
Select what type of change your PR is:
β Checklist
Before you submit your pull request, please make sure you have completed the following steps:
For more information about code review checklists, see the Code Review Checklist.