From 7c160cb6d819e535399ec75de71c00ff75757132 Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 19 Sep 2023 14:26:55 +0200 Subject: [PATCH 1/2] Allow dynamic axis when exporting to ONNX, instead if fixed input --- src/anomalib/deploy/export.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/anomalib/deploy/export.py b/src/anomalib/deploy/export.py index 1f16759b22..2cef4b5093 100644 --- a/src/anomalib/deploy/export.py +++ b/src/anomalib/deploy/export.py @@ -159,6 +159,10 @@ def export_to_onnx(model: AnomalyModule, input_size: tuple[int, int], export_pat torch.zeros((1, 3, *input_size)).to(model.device), str(onnx_path), opset_version=11, + dynamic_axes={ + 'input' : {0 : 'batch_size'}, + 'output' : {0 : 'batch_size'} + }, input_names=["input"], output_names=["output"], ) From f56e19c4c97bc8270199bcc89d90323e78fa2e29 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Tue, 19 Sep 2023 16:08:19 +0100 Subject: [PATCH 2/2] Update src/anomalib/deploy/export.py --- src/anomalib/deploy/export.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/anomalib/deploy/export.py b/src/anomalib/deploy/export.py index 2cef4b5093..0a9cfc8aac 100644 --- a/src/anomalib/deploy/export.py +++ b/src/anomalib/deploy/export.py @@ -159,10 +159,7 @@ def export_to_onnx(model: AnomalyModule, input_size: tuple[int, int], export_pat torch.zeros((1, 3, *input_size)).to(model.device), str(onnx_path), opset_version=11, - dynamic_axes={ - 'input' : {0 : 'batch_size'}, - 'output' : {0 : 'batch_size'} - }, + dynamic_axes={"input": {0: "batch_size"}, "output": {0: "batch_size"}}, input_names=["input"], output_names=["output"], )