Skip to content
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

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

danylo-boiko
Copy link
Contributor

@danylo-boiko danylo-boiko commented Feb 27, 2024

πŸ“ Description

✨ Changes

Select what type of change your PR is:

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • πŸ”¨ Refactor (non-breaking change which refactors the code base)
  • πŸš€ New feature (non-breaking change which adds functionality)
  • πŸ’₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ“š Documentation update
  • πŸ”’ Security update

βœ… Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • πŸ“‹ I have summarized my changes in the CHANGELOG and followed the guidelines for my type of change (skip for minor changes, documentation updates, and test enhancements).
  • πŸ“š I have made the necessary updates to the documentation (if applicable).
  • πŸ§ͺ I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).

For more information about code review checklists, see the Code Review Checklist.

danylo-boiko and others added 6 commits February 27, 2024 20:53
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>
@danylo-boiko
Copy link
Contributor Author

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.

@ashwinvaidya17
Copy link
Collaborator

@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>
@github-actions github-actions bot added the Docs label Feb 28, 2024
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Copy link

Check out this pull request onΒ  ReviewNB

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>
@danylo-boiko danylo-boiko marked this pull request as ready for review February 28, 2024 23:14
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a 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!

README.md Outdated
datamodule = MVTec()
model = Patchcore()
engine = Engine()
engine = Engine(model=Patchcore())
Copy link
Contributor

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.

Copy link
Contributor

@samet-akcay samet-akcay left a 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"])
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif not self.model:
if not self.model:

Copy link
Contributor Author

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?

Comment on lines 648 to 650
>>> engine = Engine(model=model)
>>> engine.fit(datamodule=datamodule)
>>> engine.test(datamodule=datamodule)
Copy link
Contributor

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.

@samet-akcay samet-akcay added Enhancement New feature or request Requires Changes Reviewers request changes, which should be addressed by the PR maker Engine and removed Inference Tests Tools Notebooks Docs labels Mar 18, 2024
Signed-off-by: Danylo Boiko <danielboyko02@gmail.com>
@danylo-boiko
Copy link
Contributor Author

Thanks for creating this PR. I've got some comments, but would also like to hear @djdameln's opinions.

Thank you for your feedback, I have made the necessary changes.

@danylo-boiko
Copy link
Contributor Author

@samet-akcay, could you please take a look at the changes/comments when you have some free time?

@samet-akcay samet-akcay modified the milestones: v1.1.0, v1.2.0 May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Engine Enhancement New feature or request Inference Notebooks Requires Changes Reviewers request changes, which should be addressed by the PR maker Tests Tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants