-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚙️Enable generic exporting of a trained model to ONNX or OpenVINO IR (#…
…509) * Moving export and convert functionality to a more generic implementation where user can get just ONNX model or ONNX model + OpenVINO IR format * Updating CLI to support generic exporting to ONNX or OpenVINO * Changed logging statement * Updated config files to use new export mode format * Test case for exporting model to ONNX and OpenVINO IR format * Updated benchmarking convert * fixed import * Fixed test cases for exporting model * Updated export_convert API to use new export mode * Adding more informed message to user on failed test case * Changed default in config to null and adding comment for options for users to select * Reduced code duplication * reducded code duplication in cli * Single path for export_convert\ * Fixing for Windows paths
- Loading branch information
1 parent
d6951eb
commit ac55462
Showing
21 changed files
with
119 additions
and
90 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
File renamed without changes.
This file contains 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
File renamed without changes.
55 changes: 55 additions & 0 deletions
55
tests/pre_merge/utils/callbacks/export_callback/test_export.py
This file contains 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,55 @@ | ||
import os | ||
import tempfile | ||
|
||
import pytest | ||
import pytorch_lightning as pl | ||
from pytorch_lightning.callbacks.early_stopping import EarlyStopping | ||
|
||
from anomalib.utils.callbacks.export import ExportCallback | ||
from tests.helpers.config import get_test_configurable_parameters | ||
from tests.pre_merge.utils.callbacks.export_callback.dummy_lightning_model import ( | ||
DummyLightningModule, | ||
FakeDataModule, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"export_mode", | ||
["openvino", "onnx"], | ||
) | ||
def test_export_model_callback(export_mode): | ||
"""Tests if an optimized model is created.""" | ||
|
||
config = get_test_configurable_parameters( | ||
config_path="tests/pre_merge/utils/callbacks/export_callback/dummy_config.yml" | ||
) | ||
|
||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
config.project.path = tmp_dir | ||
model = DummyLightningModule(hparams=config) | ||
model.callbacks = [ | ||
ExportCallback( | ||
input_size=config.model.input_size, | ||
dirpath=os.path.join(tmp_dir), | ||
filename="model", | ||
export_mode=export_mode, | ||
), | ||
EarlyStopping(monitor=config.model.metric), | ||
] | ||
datamodule = FakeDataModule() | ||
trainer = pl.Trainer( | ||
gpus=1, | ||
callbacks=model.callbacks, | ||
logger=False, | ||
checkpoint_callback=False, | ||
max_epochs=1, | ||
val_check_interval=3, | ||
) | ||
trainer.fit(model, datamodule=datamodule) | ||
|
||
if "openvino" in export_mode: | ||
assert os.path.exists(os.path.join(tmp_dir, "openvino/model.bin")), "Failed to generate OpenVINO model" | ||
elif "onnx" in export_mode: | ||
assert os.path.exists(os.path.join(tmp_dir, "model.onnx")), "Failed to generate ONNX model" | ||
else: | ||
raise ValueError(f"Unknown export_mode {export_mode}. Supported modes: onnx or openvino.") |
40 changes: 0 additions & 40 deletions
40
tests/pre_merge/utils/callbacks/openvino_callback/test_openvino.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.