pytorch导出onnx格式时报错,RuntimeError: Failed to export an ONNX attribute, since it's not constant, please

运行程序,Pytorch版YOLOv3,链接地址:

https://github.com/eriklindernoren/PyTorch-YOLOv3

Pytorch版本:1.1.0

 

onnx转换程序:

import torch
import torchvision
from models import *
import argparse


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--model_def", type=str, default="config/yolov3-tiny.cfg", help="path to model definition file")
    opt = parser.parse_args()
    dummy_input = torch.randn(1, 3, 416, 416)
    model = Darknet(opt.model_def)
    torch.onnx.export(model, dummy_input, "yolov3.onnx", verbose=True)


if __name__ == '__main__':
    main()

错误提示:

File "D:\Anaconda3\lib\site-packages\torch\onnx\symbolic.py", line 90, in _parse_arg
    raise RuntimeError("Failed to export an ONNX attribute, "
RuntimeError: Failed to export an ONNX attribute, since it's not constant, please try to make things (e.g., kernel size) static if possible
 

解决办法:

1.我将pytorch更新到了,当前最新版本pytorch1.2.0,这个问题自己解决了

2.下面这个人将pytorch推到了1.0.1版,

https://www.lizenghai.com/archives/15436.html

总体而言,应该是pytorch版本的问题

 

 

 

你可能感兴趣的:(工作经验,YOLOv3,pytorch,onnx)