-
Notifications
You must be signed in to change notification settings - Fork 846
feat(engine): Support barebones Mode for Engine #3189
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
Open
rajeshgangireddy
wants to merge
7
commits into
open-edge-platform:main
Choose a base branch
from
rajeshgangireddy:fixes/barebones
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b9cef09
feat(engine) : Support barebones mode for engine
rajeshgangireddy c91b7ce
Merge branch 'main' into fixes/barebones
rajeshgangireddy e64dab2
docs(callbacks): Add note about ModelCheckpoint in barebones mode
rajeshgangireddy 644fcca
feat(barebones): Add examples for training modes and checkpoint control
rajeshgangireddy 32de199
feat(barebones): Add example for barebones training mode with metricsβ¦
rajeshgangireddy 1154ab4
refactor(barebones): Remove duplicate file
rajeshgangireddy d9ccb8b
fix(barebones): make copilot happy
rajeshgangireddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """Training modes and checkpoint control examples. | ||
| This example demonstrates different training modes in Anomalib: | ||
| 1. Standard training with default checkpointing | ||
| 2. Custom checkpoint callback configuration | ||
| 3. Barebones mode for fast training/testing without checkpoint overhead | ||
| Note: | ||
| Under the hood, `Engine` uses Lightning's `Trainer` to manage the training | ||
| workflow. So, most Trainer arguments can be passed to the Engine constructor. | ||
| This includes parameters like | ||
| `max_epochs`, `enable_checkpointing`, `barebones`, `logger`, `callbacks`, etc. | ||
| For more details on available parameters, see: | ||
| https://lightning.ai/docs/pytorch/stable/common/trainer.html | ||
| """ | ||
|
|
||
| # Copyright (C) 2024 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from anomalib.callbacks import ModelCheckpoint | ||
| from anomalib.data import MVTecAD | ||
| from anomalib.engine import Engine | ||
| from anomalib.models import Fre | ||
|
|
||
| # Initialize model and data | ||
| model = Fre() | ||
| datamodule = MVTecAD(category="bottle") | ||
|
|
||
| print("1. Standard Training with Default Checkpointing") | ||
| print("-" * 50) | ||
| # 1. Standard training (checkpoints saved automatically) | ||
| engine = Engine(max_epochs=5) | ||
| engine.fit(model=model, datamodule=datamodule) | ||
|
|
||
| print(f"Checkpoint saved at: {engine.best_model_path}") | ||
|
|
||
|
|
||
| # 2. Custom checkpoint callback | ||
| # Example: don't save any checkpoints (useful for quick tests) | ||
|
|
||
| print("2. Custom Checkpoint Callback") | ||
| print("-" * 50) | ||
| checkpoint_callback = ModelCheckpoint(save_top_k=0) | ||
|
|
||
| engine = Engine(max_epochs=5, callbacks=[checkpoint_callback]) | ||
| print("Training with custom checkpoint callback...") | ||
| engine.fit(model=model, datamodule=datamodule) | ||
| print(f"Checkpoint path: {engine.best_model_path}") | ||
| print() | ||
|
|
||
|
|
||
| # 3. Barebones Mode for Maximum Speed | ||
| # Barebones mode: minimal overhead, no checkpointing, no model summary, etc. | ||
| # Useful for benchmarking with minimal overhead. | ||
| # See Lightning docs: https://lightning.ai/docs/pytorch/stable/common/trainer.html#barebones | ||
|
|
||
| print("3. Barebones Training Mode") | ||
| print("-" * 50) | ||
|
|
||
| # Initialize model and data | ||
| model = Fre() | ||
| datamodule = MVTecAD(category="bottle") | ||
|
|
||
| # Create engine with barebones mode enabled | ||
| engine = Engine( | ||
| max_epochs=5, | ||
| barebones=True, # Minimal overhead, no checkpoint saving | ||
| ) | ||
|
|
||
| # Train in barebones mode | ||
| print("Training in barebones mode (fastest)...") | ||
| engine.fit(model=model, datamodule=datamodule) | ||
|
|
||
| # Metrics are still captured and returned even in barebones mode | ||
| print("\nTesting and retrieving metrics...") | ||
| results = engine.test(model=model, datamodule=datamodule) | ||
|
|
||
| # Print results | ||
| print("\nTest Results:") | ||
| for metric, value in results[0].items(): | ||
| print(f"{metric}: {value:.4f}") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.