Skip to content

TorchVision Detection Models fail to export to onnx with dynamo=True #9306

@RajeevSekar

Description

@RajeevSekar

Description

TorchVision detection models (Faster R-CNN, RetinaNet, etc.) cannot be exported to ONNX using dynamo=True in torch.onnx.export(), while classification models export successfully.

Reproduction

import torch
import torchvision.models as models

model = models.detection.fasterrcnn_resnet50_fpn(weights='DEFAULT')
model.eval()

dummy_input = torch.randn(1, 3, 224,224)

torch.onnx.export(
model,
dummy_input,
"fasterrcnn.onnx",
opset_version=18,
input_names=['input'],
output_names=['output'],
dynamo=True
)

Error

torch.onnx.OnnxExporterError: Failed to export the model with torch.export().
This is step 1/3 of exporting the model to ONNX.

Versions

Collecting environment information...
PyTorch version: 2.7.1+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11 Pro (10.0.26100 64-bit)
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 3.31.9
Libc version: N/A

Python version: 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.26100-SP0
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Name: Genuine Intel(R) 0000
Manufacturer: GenuineIntel
Family: 1
Architecture: 9
ProcessorType: 3
DeviceID: CPU0
CurrentClockSpeed: 1600
MaxClockSpeed: 1600
L2CacheSize: 16384
L2CacheSpeed: None
Revision: None

Versions of relevant libraries:
[pip3] flake8==7.3.0
[pip3] flake8-annotations-complexity==0.1.0
[pip3] flake8-broken-line==1.0.0
[pip3] flake8-bugbear==24.12.12
[pip3] flake8-builtins==2.5.0
[pip3] flake8-class-attributes-order==0.3.0
[pip3] flake8-coding==1.3.2
[pip3] flake8-comprehensions==3.16.0
[pip3] flake8-debugger==4.1.2
[pip3] flake8-docstrings==1.7.0
[pip3] flake8-eradicate==1.5.0
[pip3] flake8-executable==2.1.3
[pip3] flake8-expression-complexity==0.0.11
[pip3] flake8-pep3101==2.1.0
[pip3] flake8-plugin-utils==1.3.3
[pip3] flake8-print==5.0.0
[pip3] flake8-pytest-style==2.1.0
[pip3] flake8-quotes==3.4.0
[pip3] flake8-rst-docstrings==0.3.1
[pip3] flake8-string-format==0.3.0
[pip3] flake8-variables-names==0.0.6
[pip3] mypy==1.16.1
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.2.6
[pip3] onnx==1.18.0
[pip3] onnxruntime==1.22.1
[pip3] torch==2.7.1
[conda] Could not collect

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions