Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

动态batch推理 #9

Open
pangedeshijie opened this issue Apr 13, 2023 · 6 comments
Open

动态batch推理 #9

pangedeshijie opened this issue Apr 13, 2023 · 6 comments

Comments

@pangedeshijie
Copy link

你好,博主,很感谢你的项目代码,目前在用这个代码的时候遇到一点问题,我在导出onnx的时候,设置了动态batch,基于yolov5和yolov7的版本,都做了尝试,发现报了同样的错误,在多张图片同时进行推理的时候
Reshape node. Name:'/model.1/Reshape' Status Message: D:\a_work\1\s\onnxruntime\core\providers\cpu\tensor\reshape_helper.h:41 onnxruntime::ReshapeHelper::ReshapeHelper gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{2,96,80,80}, requested shape:{1,2,48,80,80}
看着像是在某个节点reshape的时候报错了,yolov5和v7都是在同样的节点,想问下博主这种情况怎么解决?还是我操作的有问题?

@wangat
Copy link

wangat commented Apr 18, 2023

我也遇到了相同的问题,可视化发现concat和reshape算子那边有点问题,onnxruntime测试也是,最后定位在common.py的channel_shuffle这边,需要把batch_size设置为-1,其他对应修改就可以了。

@pangedeshijie
Copy link
Author

哥们,很感谢你提供的解决方案,这个common.py是修改完后,需要重新训练一下模型吗?还是在导出为onnx的时候修改?

@pangedeshijie
Copy link
Author

我也遇到了相同的问题,可视化发现concat和reshape算子那边有点问题,onnxruntime测试也是,最后定位在common.py的channel_shuffle这边,需要把batch_size设置为-1,其他对应修改就可以了。
哥们,很感谢你提供的解决方案,这个common.py是修改完后,需要重新训练一下模型吗?还是在导出为onnx的时候修改?

@wangat
Copy link

wangat commented Apr 26, 2023

哥们,很感谢你提供的解决方案,这个common.py是修改完后,需要重新训练一下模型吗?还是在导出为onnx的时候修改?

应该不需要重新训练,导出的时候修改就可以。

@pangedeshijie
Copy link
Author

def channel_shuffle(x, groups):
batchsize, num_channels, height, width = x.data.size()
channels_per_group = num_channels // groups

batchsize = -1

# reshape
x = x.view(batchsize, groups, channels_per_group, height, width)
x = torch.transpose(x, 1, 2).contiguous()

# flatten

x = x.view(batchsize, -1, height, width)
return x

哥们,你好,我在这个地方做了一下修改,导出的时候报错了,你那边具体是怎么修改的 方便说一下吗?

x = x.view(batchsize, -1, height, width)

RuntimeError: only one dimension can be inferred

@wangat
Copy link

wangat commented Apr 26, 2023

x = x.view(batchsize, -1, height, width)
-1是自动计算的意思,所以只能有1个,bs是-1了,第二项就不能再是-1了,我改成(batchsize,groups*channels_per_group,height,width)了,数字固定了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants