解决the operator silu to ONNX opset version 12 is not supported问题

问题:使用yolov5-7.0的export.py导出onnx文件时报错

原因:低版本的opset不支持切片操作

解决方法:在export.py种找到torch.onnx.export,更改版本为11

 torch.onnx.export(
        model.cpu() if dynamic else model,  # --dynamic only compatible with cpu
        im.cpu() if dynamic else im,
        f,
        verbose=False,
        opset_version=11, #只需要改这行,版本改为11
        do_constant_folding=True,
        input_names=['images'],
        output_names=output_names,
        dynamic_axes=dynamic or None)

 再次运行export.py发现仍然报错the operator silu to ONNX opset version 11 is not supported

解决方法:查看python解释器

我的环境是虚拟环境py38,于是到py38中依次找到以下路径

D:\anaconda\envs\py38\Lib\site-packages\torch\nn\modules\ activation.py

打开activation.py找到第394行代码修改

    def forward(self, input: Tensor) -> Tensor:
        return input * torch.sigmoid(input)#改成这一行代码
        # return F.silu(input, inplace=self.inplace)这是原代码

再次运行export.py

成功 

猜你喜欢

转载自blog.csdn.net/qq_43450443/article/details/130053363
今日推荐