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

Update setup logic in model and datamodule #1794

Merged
merged 2 commits into from
Feb 29, 2024

Conversation

djdameln
Copy link
Contributor

@djdameln djdameln commented Feb 29, 2024

📝 Description

Minor change in how we check if self._setup should be called in setup. The change is repeated in both the datamodule and the anomaly module. This is mainly to ensure that we can use the modules in a standalone fashion, without/before being attached to a trainer. For example, we could use the following to quickly inspect the images in our datamodule.

>>> from anomalib.data import MVTec
>>>
>>> datamodule = MVTec(image_size=(512, 512))
>>> datamodule.setup()
>>>
>>> sample = next(iter(datamodule.train_dataloader()))
>>> sample["image"].shape
torch.Size([32, 3, 512, 512])

Similarly, we could inspect the structure of the torch model of a given Lightning model after invoking setup:

>>> from anomalib.models import Ganomaly
>>>
>>> model = Ganomaly()
>>> model.setup()
>>>
>>> model.model.generator.encoder1.input_layers
Sequential(
  (initial-conv-3-64): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(4, 4), bias=False)
  (initial-relu-64): LeakyReLU(negative_slope=0.2, inplace=True)
)

Without the current change, this would lead to problems downstream when the entrypoints of the engine are called.

✨ 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.

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, only a single comment...

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.

Great, thanks!

@ashwinvaidya17 ashwinvaidya17 merged commit 2e99ecd into openvinotoolkit:main Feb 29, 2024
6 of 7 checks passed
@djdameln djdameln deleted the update-setup-logic branch December 4, 2024 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants