yolov5将pt模型导出为onnx
- 修改项目源码目录下的export.py文件:
- parse_opt函数中--data的默认值更改为数据集的配置文件
- parse_opt函数中--weights的默认值更改为需要转换的pt模型的路径
- parse_opt函数中--include的默认值更改为["onnx"]
- 安装onnx依赖:
pip install onnx==1.12.0
- 执行
python export.py --dynamic
YOLOv5模型推理过程中报错cannot instantiate ‘PosixPath‘ on your system
- 将环境下的pathlib.py文件中如下内容更改
def __new__(cls, *args, **kwargs):
# 修改前
# if cls is Path:
# cls = WindowsPath if os.name == 'nt' else PosixPath
# self = cls._from_parts(args, init=False)
# if not self._flavour.is_supported:
# raise NotImplementedError("cannot instantiate %r on your system"
# % (cls.__name__,))
# self._init()
# return self
# 修改后
if cls is Path:
# cls = WindowsPath if os.name == 'nt' else PosixPath
cls = WindowsPath
self = cls._from_parts(args, init=False)
# Windows doesn't support PosixPath
if type(self) == PosixPath:
cls = WindowsPath
self = cls._from_parts(args, init=False)
if not self._flavour.is_supported:
raise NotImplementedError("cannot instantiate %r on your system"
% (cls.__name__,))
self._init()
return self