-
-
Notifications
You must be signed in to change notification settings - Fork 425
Description
When running the utils/export_yolo11.py script, the export process fails with a ModuleNotFoundError because recent versions of PyTorch (torch) have a new, unlisted dependency for their ONNX exporter.
The torch.onnx.export() function now defaults to using the dynamo exporter, which internally requires the onnxscript library. Since this library isn't listed as a dependency, the script crashes.
How to Reproduce
This bug can be reliably reproduced in any clean Python environment (like a Docker container) that installs the latest versions of the required libraries.
- Set up an environment with
python3-pip,git, andtorch. - Clone this repository:
git clone https://github.com/marcoslucianops/DeepStream-Yolo.git - Install the other dependencies:
pip3 install ultralytics onnx onnxslim onnxruntime - Get a model file (e.g.,
yolo11x.pt) - Try to run the export script:
python3 DeepStream-Yolo/utils/export_yolo11.py -w yolo11x.pt - The script will fail with the following traceback:
Traceback (most recent call last): File ".../DeepStream-Yolo/utils/export_yolo11.py", line 141, in <module> main(args) File ".../DeepStream-Yolo/utils/export_yolo11.py", line 107, in main torch.onnx.export( ... File "/usr/local/lib/python3.10/dist-packages/torch/onnx/_internal/exporter/_core.py", line 18, in <module> import onnxscript ModuleNotFoundError: No module named 'onnxscript'
Proposed Fix
Force the Legacy Exporter (Code Change)
A code-level fix is to modify utils/export_yolo11.py to force PyTorch to use the legacy (TorchScript-based) exporter, which does not require onnxscript.
This is done by adding dynamo=False to the torch.onnx.export() call (around line 107):
Current Code:
torch.onnx.export(
model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset, do_constant_folding=True,
input_names=['input'], output_names=['output'], dynamic_axes=dynamic_axes if args.dynamic else None
)Fixed Code:
torch.onnx.export(
model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset, do_constant_folding=True,
input_names=['input'], output_names=['output'], dynamic_axes=dynamic_axes if args.dynamic else None,
dynamo=False # <-- Add this argument
)This makes the script compatible with newer PyTorch versions without requiring an extra dependency.