最近在使用yolov5把pt模型转为onnx格式的时候,报错了
(yolo5) E:\code\v5>python export.py --weights yolov5s.pt --include onnx
export: data=train.yaml, weights=['yolov5s.pt'], imgsz=[640, 640], batch_size=1, device=, half=False, inplace=False, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx']
YOLOv5 2022-12-26 Python-3.8.20 torch-2.4.1+cpu CPU
E:\code\v5\models\experimental.py:79: FutureWarning: You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
ckpt = torch.load(attempt_download(w), map_location='cpu') # load
Fusing layers...
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs
PyTorch: starting from yolov5s.pt with output shape (1, 25200, 85) (14.1 MB)
ONNX: export failure 2.5s: DLL load failed while importing onnx_cpp2py_export: (DLL)
问题:
onnx的版本不匹配
解决方案:
卸载安装另一个版本
pip uninstall onnx
安装如下指定版本
pip install onnx==1.16.1 -i https://mirrors.aliyun.com/pypi/simple/
然后重新执行转换就好了
python export.py --weights yolov5s.pt --include onnx --opset 12 --simplify