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

Fix Export docstring in CLI #2058

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/anomalib/cli/utils/help_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"validate": {"model", "model.help", "data", "data.help", "ckpt_path", "config"},
"test": {"model", "model.help", "data", "data.help", "ckpt_path", "config"},
"predict": {"model", "model.help", "data", "data.help", "ckpt_path", "config"},
"export": {"model", "model.help", "export_type", "ckpt_path", "config"},
}

try:
Expand All @@ -31,6 +32,7 @@
"validate": Engine.validate,
"test": Engine.test,
"predict": Engine.predict,
"export": Engine.export,
}
except ImportError:
print("To use other subcommand using `anomalib install`")
Expand Down
20 changes: 12 additions & 8 deletions src/anomalib/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,14 @@ def train(
def export(
self,
model: AnomalyModule,
export_type: ExportType,
export_type: ExportType | str,
export_root: str | Path | None = None,
input_size: tuple[int, int] | None = None,
transform: Transform | None = None,
ov_args: dict[str, Any] | None = None,
ckpt_path: str | Path | None = None,
) -> Path | None:
"""Export the model in PyTorch, ONNX or OpenVINO format.
r"""Export the model in PyTorch, ONNX or OpenVINO format.

Args:
model (AnomalyModule): Trained model.
Expand All @@ -882,7 +882,8 @@ def export(
input_size (tuple[int, int] | None, optional): A statis input shape for the model, which is exported to ONNX
and OpenVINO format. Defaults to None.
transform (Transform | None, optional): Input transform to include in the exported model. If not provided,
the engine will try to use the transform from the datamodule or dataset. Defaults to None.
the engine will try to use the default transform from the model.
Defaults to ``None``.
ov_args (dict[str, Any] | None, optional): This is optional and used only for OpenVINO's model optimizer.
Defaults to None.
ckpt_path (str | Path | None): Checkpoint path. If provided, the model will be loaded from this path.
Expand All @@ -897,22 +898,25 @@ def export(
CLI Usage:
1. To export as a torch ``.pt`` file you can run the following command.
```python
anomalib export --model Padim --export_mode TORCH --data MVTec
anomalib export --model Padim --export_mode torch --ckpt_path <PATH_TO_CHECKPOINT>
```
2. To export as an ONNX ``.onnx`` file you can run the following command.
```python
anomalib export --model Padim --export_mode ONNX --data Visa --input_size "[256,256]"
anomalib export --model Padim --export_mode onnx --ckpt_path <PATH_TO_CHECKPOINT> \
--input_size "[256,256]"
```
3. To export as an OpenVINO ``.xml`` and ``.bin`` file you can run the following command.
```python
anomalib export --model Padim --export_mode OPENVINO --data Visa --input_size "[256,256]"
anomalib export --model Padim --export_mode openvino --ckpt_path <PATH_TO_CHECKPOINT> \
--input_size "[256,256]"
```
4. You can also overrride OpenVINO model optimizer by adding the ``--ov_args.<key>`` arguments.
```python
anomalib export --model Padim --export_mode OPENVINO --data Visa --input_size "[256,256]" \
--ov_args.compress_to_fp16 False
anomalib export --model Padim --export_mode openvino --ckpt_path <PATH_TO_CHECKPOINT> \
--input_size "[256,256]" --ov_args.compress_to_fp16 False
```
"""
export_type = ExportType(export_type)
self._setup_trainer(model)
if ckpt_path:
ckpt_path = Path(ckpt_path).resolve()
Expand Down
Loading