程序顽童进化史 2021-10-15 15:08 采纳率: 0%
浏览 360

yolov5-4.0训练模型pt文件转onnx出现的问题:Process finished with exit code -1073741819 (0xC0000005)

环境:
pytorch1.7.1 cuda10.1 opencv4.5.3 vs2019
首先:看了网上很多教程,要修改focus函数的实现方式,具体修改如下:
modols/commen.py,原因是onnx不支持切片操作,focus中原有的::2这样的操作是无法转出的。办法就是利用common函数中子带的
Contract操作。


class Focus(nn.Module):
    # Focus wh information into c-space
    def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):  # ch_in, ch_out, kernel, stride, padding, groups
        super(Focus, self).__init__()
        self.conv = Conv(c1 * 4, c2, k, s, p, g, act)

    def forward(self, x):  # x(b,c,w,h) -> y(b,4c,w/2,h/2)
        # return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) #修改前
        #============修改后=================#
        contract = Contract(gain=2)
        return self.conv(contract(x))

之后,在官方自带的models/export.py中转出。
终端输出:

Namespace(batch_size=1, img_size=[640, 640], weights='./yolov5s.pt')
Fusing layers... 
Model Summary: 224 layers, 7266973 parameters, 0 gradients, 17.0 GFLOPS
A:\Anaconda\envs\Torch17\lib\site-packages\torch\jit\_trace.py:940: TracerWarning: Encountering a list at the output of the tracer might cause the trace to be incorrect, this is only valid if the container structure does not change based on the module's inputs. Consider using a constant container instead (e.g. for `list`, use a `tuple` instead. for `dict`, use a `NamedTuple` instead). If you absolutely need this and know the side effects, pass strict=False to trace() to allow this behavior.
  _force_outplace,
TorchScript export success, saved as ./yolov5s.torchscript.pt
Starting ONNX export with onnx 1.8.1...
Process finished with exit code -1073741819 (0xC0000005)

转出程序就触发终止了,报此类错误,并不明白为什么。看别的文章有说是win10更新了驱动,导致目前的NVCUDA64.DLL版本与nvcc-V查看的不一致,目前确实有这个情况,我目前NVIDA控制面板中的驱动显示版本11.1,nvcc-V 显示CUDA10.1;但是网络训练和推理都没问题,就转ONNX的时候出现这个问题,我觉得不是pytorch版本问题吧。希望有想法的朋友指导一下,是源码哪里设置输入有问题吗?

  • 写回答

1条回答 默认 最新

  • 爱晚乏客游 2021-10-15 15:37
    关注

    onnx换成1.7.0的版本看看,不行的话换成yolov5-v5最新版本,一样的修改方法导出来看看能不能导出onnx文件

    评论

报告相同问题?

问题事件

  • 创建了问题 10月15日

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的