pytorch / pytorch/vision

FasterRcnn conversion to ONNX example fails

Open
#8,734 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🐛 Describe the bug

Found in this example
https://github.com/pytorch/vision/blob/e65a857b5487a8493bc8a80a95d64d9f049de347/torchvision/models/detection/faster_rcnn.py#L373

Following this example, the onnx conversion fails. I get this error:

11/18/2024-22:21:39] [I] [TRT] Input filename:   faster_rcnn.onnx
[11/18/2024-22:21:39] [I] [TRT] ONNX IR version:  0.0.6
[11/18/2024-22:21:39] [I] [TRT] Opset version:    11
[11/18/2024-22:21:39] [I] [TRT] Producer name:    pytorch
[11/18/2024-22:21:39] [I] [TRT] Producer version: 1.11.0
[11/18/2024-22:21:39] [I] [TRT] Domain:           
[11/18/2024-22:21:39] [I] [TRT] Model version:    0
[11/18/2024-22:21:39] [I] [TRT] Doc string:       
[11/18/2024-22:21:39] [I] [TRT] ----------------------------------------------------------------
[11/18/2024-22:21:39] [E] Error[4]: ITensor::getDimensions: Error Code 4: Shape Error (reshape wildcard -1 has infinite number of solutions or no solution. Reshaping [0,364] to [0,-1].)
[11/18/2024-22:21:39] [E] [TRT] parsers/onnx/ModelImporter.cpp:944: While parsing node number 1826 [Reshape -> "rel_codes.3"]:
[11/18/2024-22:21:39] [E] [TRT] parsers/onnx/ModelImporter.cpp:947: --- Begin node ---
input: "box_regression"
input: "onnx::Reshape_3184"
output: "rel_codes.3"
name: "Reshape_1882"
op_type: "Reshape"

[11/18/2024-22:21:39] [E] [TRT] parsers/onnx/ModelImporter.cpp:948: --- End node ---
[11/18/2024-22:21:39] [E] [TRT] parsers/onnx/ModelImporter.cpp:950: ERROR: parsers/onnx/ModelImporter.cpp:197 In function parseNode:
[6] Invalid Node - Reshape_1882
ITensor::getDimensions: Error Code 4: Shape Error (reshape wildcard -1 has infinite number of solutions or no solution. Reshaping [0,364] to [0,-1].)
[11/18/2024-22:21:39] [E] Failed to parse onnx file
[11/18/2024-22:21:39] [I] Finished parsing network model. Parse time: 0.192799
[11/18/2024-22:21:39] [E] Parsing model failed
[11/18/2024-22:21:39] [E] Failed to create engine from model or file.
[11/18/2024-22:21:39] [E] Engine set up failed
&&&& FAILED TensorRT.trtexec [TensorRT v100600] [b26] # trtexec --onnx=faster_rcnn.onnx --saveEngine=test_engine.trt
Versions
Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: 14.0.0-1ubuntu1.1
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-48-generic-x86_64-with-glibc2.35
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA RTX A6000
Nvidia driver version: 550.120
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        48 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               32
On-line CPU(s) list:                  0-31
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen 9 7950X 16-Core Processor
CPU family:                           25
Model:                                97
Thread(s) per core:                   2
Core(s) per socket:                   16
Socket(s):                            1
Stepping:                             2
CPU max MHz:                          5881.0000
CPU min MHz:                          400.0000
BogoMIPS:                             8983.10
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                       AMD-V
L1d cache:                            512 KiB (16 instances)
L1i cache:                            512 KiB (16 instances)
L2 cache:                             16 MiB (16 instances)
L3 cache:                             64 MiB (2 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-31
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Mitigation; Safe RET
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==2.1.1
[conda] numpy                     1.26.4                   pypi_0    pypi

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Faster R-CNN ONNX conversion example in torchvision/models/detection/faster_rcnn.py around line 373 and reproduce the reported conversion. Inspect the generated faster_rcnn.onnx and the TensorRT trtexec failure at the Reshape node. Done means the documented example produces an ONNX model that TensorRT can parse successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.