WongKinYiu / yolor

implementation of paper - You Only Learn One Representation: Unified Network for Multiple Tasks (https://arxiv.org/abs/2105.04206)
GNU General Public License v3.0
1.98k stars 524 forks source link

Unexpected output shape of onnx model #37

Closed Fschoeller closed 3 years ago

Fschoeller commented 3 years ago

Hi! i'm on the paper branch and have exported a yolor-p6 model to onnx using models/export.py. The onnx model has the output shape output: batch, 3, 96, 160, nc though I expected the shape output: batch, 3, max_boxes, nc Am I doing anything wrong? Thanks!

Fschoeller commented 3 years ago

Solved by commenting out line 44 in export model.model[-1].export = True # set Detect() layer export=True and using inplace operation during export:

if self.inplace:
    y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + self.grid[i]) * self.stride[i]  # xy
    y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i]  # wh
jnskplr commented 2 years ago

Hi,

I'm using paper branch too and exported my model to onnx. Having the same issue with output shape and tried to follow your steps.

I don't really get what you're meaning with the inplace operation. Where did you insert it into your code, I guess in forward() function of IDetect() class in yolo.py? And what else did you adjust there? Maybe you can provide your yolo.py file.

Thanks and best regards.

jnskplr commented 2 years ago

Solved it for me, the way is almost the same just a little bit different. #207