加载自定义训练YOLOv7模型时遇TypeError: custom()意外参数'path'
YOLOv7加载自定义权重报错解决方法
问题场景
执行以下代码加载自定义数据集训练的YOLOv7权重时出现报错:
model = torch.hub.load('yolov7','custom', path='/home/runs/train/yolov7x-custom/weights/best.pt',force_reload=True,source='local')
报错信息:TypeError: custom() got an unexpected keyword argument 'path'
解决方法
问题出在参数名错误——YOLOv7的custom方法接收的权重路径参数是path_or_model,而非path。修改代码如下:
model = torch.hub.load('yolov7','custom', path_or_model='/home/runs/train/yolov7x-custom/weights/best.pt', force_reload=True, source='local')
额外注意事项
- 确认
source='local'指向的本地YOLOv7仓库路径正确 - 检查
best.pt文件的路径是否存在且无误
内容的提问来源于stack exchange,提问作者Yashas Hittalmakki
相关产品推荐
相关产品推荐

