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

Fixed bug of no saving simplified ONNX file #1489

Merged
merged 2 commits into from
Sep 27, 2023
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
14 changes: 11 additions & 3 deletions src/super_gradients/module_interfaces/exportable_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Union, Optional, List, Tuple

import numpy as np
import onnx
import onnxsim
import torch
from torch import nn, Tensor
Expand Down Expand Up @@ -495,9 +496,12 @@ def export(
if onnx_simplify:
# If TRT engine is used, we need to run onnxsim.simplify BEFORE attaching NMS,
# because EfficientNMS_TRT is not supported by onnxsim and would lead to a runtime error.
onnxsim.simplify(output)
model_opt, simplify_successful = onnxsim.simplify(output)
if not simplify_successful:
raise RuntimeError(f"Failed to simplify ONNX model {output} with onnxsim. Please check the logs for details.")
onnx.save(model_opt, output)
logger.debug(f"Ran onnxsim.simplify on model {output}")
# Disable onnx_simplify to avoid running it twice.
# Disable onnx_simplify to avoid running it second time.
onnx_simplify = False

nms_attach_method = attach_tensorrt_nms
Expand Down Expand Up @@ -528,7 +532,11 @@ def export(
)

if onnx_simplify:
onnxsim.simplify(output)
model_opt, simplify_successful = onnxsim.simplify(output)
if not simplify_successful:
raise RuntimeError(f"Failed to simplify ONNX model {output} with onnxsim. Please check the logs for details.")
onnx.save(model_opt, output)

logger.debug(f"Ran onnxsim.simplify on {output}")
finally:
if quantization_mode == ExportQuantizationMode.INT8:
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/export_detection_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def test_export_with_fp16_quantization(self):

max_predictions_per_image = 300
with tempfile.TemporaryDirectory() as tmpdirname:
tmpdirname = "."
out_path = os.path.join(tmpdirname, "ppyoloe_s_with_fp16_quantization.onnx")

ppyolo_e: ExportableObjectDetectionModel = models.get(Models.PP_YOLOE_S, pretrained_weights="coco")
Expand Down