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

🚀from_config API: Create a path between API & configuration file (CLI) #2065

Merged

Conversation

harimkang
Copy link
Collaborator

@harimkang harimkang commented May 16, 2024

📝 Description

#1992

  • Adds from_config ,the ability to create model and datamodule instances via the Configuration file.
  • Add Engine.from_config that provide engine, model, datamodule from full-configuration files.
  • Add Unit-Test for from_config features.

How to test:

  1. Model & Data configuration to API Usage
# Import the required modules
from anomalib.data import AnomalibDataModule
from anomalib.engine import Engine
from anomalib.models import AnomalyModule

# Initialize the datamodule
# datamodule = MVTec()
data_config = "configs/data/mvtec.yaml"
datamodule = AnomalibDataModule.from_config(config_path=data_config)


# Initialize the model
# model = Patchcore()
model_config = "configs/model/patchcore.yaml"
model = AnomalyModule.from_config(config_path=model_config)


# Initialize engine
engine = Engine()

# Train the model
engine.fit(datamodule=datamodule, model=model)
  1. Full configuration Usage (Include model, data, engine, trainer args)
    Get full configuration file (output from cli - TBD or Use --print_config > configs.yaml)
(anomalib) anomalib fit --model anomalib.models.Padim --data anomalib.data.MVTec --print_config > anomalib_config.yaml

Use Configuration file with API

from anomalib.engine import Engine

config_path = "anomalib_config.yaml"
engine, model, datamodule = Engine.from_config(config_path=config_path)
engine.fit(datamodule=datamodule, model=model)

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

Signed-off-by: Kang, Harim <harim.kang@intel.com>
Signed-off-by: Kang, Harim <harim.kang@intel.com>
@harimkang harimkang changed the title Add from_config feature in model and data from_config: Create a path between API & configuration file (CLI) May 17, 2024
@harimkang harimkang changed the title from_config: Create a path between API & configuration file (CLI) 🚀from_config: Create a path between API & configuration file (CLI) May 17, 2024
@harimkang harimkang changed the title 🚀from_config: Create a path between API & configuration file (CLI) 🚀from_config API: Create a path between API & configuration file (CLI) May 17, 2024
Signed-off-by: Kang, Harim <harim.kang@intel.com>
@harimkang harimkang added this to the v1.1.0 milestone May 20, 2024
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! I have a few minor comments. But we can also look into refactoring these later on.

src/anomalib/engine/engine.py Show resolved Hide resolved
@ashwinvaidya17 ashwinvaidya17 merged commit 5ca1612 into openvinotoolkit:main May 24, 2024
7 checks passed
@harimkang harimkang deleted the harimkan/new-from-config branch May 28, 2024 00:17
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.

None yet

2 participants