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

Create meta_data.json with ONNX export as well as OpenVINO export #636

Merged
merged 6 commits into from
Oct 19, 2022
Merged
Changes from 4 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
18 changes: 9 additions & 9 deletions anomalib/deploy/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def export_convert(
export_mode: str,
export_path: Optional[Union[str, Path]] = None,
):
"""Export the model to onnx format and convert to OpenVINO IR.
"""Export the model to onnx format and convert to OpenVINO IR. Metadata.json is generated regardless of export mode.

Args:
model (AnomalyModule): Model to convert.
Expand All @@ -65,14 +65,14 @@ def export_convert(
input_names=["input"],
output_names=["output"],
)
export_path = os.path.join(str(export_path), "openvino")
ashwinvaidya17 marked this conversation as resolved.
Show resolved Hide resolved
if export_mode == "openvino":
export_path = os.path.join(str(export_path), "openvino")
optimize_command = "mo --input_model " + str(onnx_path) + " --output_dir " + str(export_path)
assert os.system(optimize_command) == 0, "OpenVINO conversion failed"
with open(Path(export_path) / "meta_data.json", "w", encoding="utf-8") as metadata_file:
meta_data = get_model_metadata(model)
# Convert metadata from torch
for key, value in meta_data.items():
if isinstance(value, Tensor):
meta_data[key] = value.numpy().tolist()
json.dump(meta_data, metadata_file, ensure_ascii=False, indent=4)
with open(Path(export_path) / "meta_data.json", "w", encoding="utf-8") as metadata_file:
meta_data = get_model_metadata(model)
# Convert metadata from torch
for key, value in meta_data.items():
if isinstance(value, Tensor):
meta_data[key] = value.numpy().tolist()
json.dump(meta_data, metadata_file, ensure_ascii=False, indent=4)