Error converting to onnx: forward function contains for loop
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
Hello, there is a for loop in my forward function. When I turned to onnx, the following error occurred:
[ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running Split node. Name:'Split_ 1277' Status Message: Cannot split using values in 'split' attribute. Axis=0 Input shape={59} NumOutputs=17 Num entries in 'split' (must equal number of outputs) was 17 Sum of sizes in 'split' (must equal size of selected axis) was 17
Part of my forward code:
y, ey, x, ex = pad(boxes, w, h)
if len(boxes) > 0:
im_data = []
indx_y = torch.where(ey > y-1)[0]
for ind in indx_y:
img_k = imgs[image_inds[ind],:, (y[ind] - 1).type(torch.int64):ey[ind].type(torch.int64), (x[ind]-1).type(torch.int64):ex[ind].type(torch.int64)].unsqueeze(0)
im_data.append(imresample(img_k, (24, 24)))
im_data = torch.cat(im_data, dim=0)
return im_data
I found that during the first onnx conversion, the for loop was executed 17 times, but when I tested it, the for loop required 59 times, so there was an error. In the forward function, indx_y is dynamic, so the number of for loops is also dynamic. Is there any way to solve this problem?
cc @neginraoof
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided forward function and reproduce the ONNX conversion using inputs where indx_y produces different numbers of iterations. Compare the conversion-time and test-time Split shapes and confirm that the resulting model handles the dynamic loop count without the reported Split mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100