下载源码准备测试模型时
(个人习惯不动源代码,都是在终端运行)
在pycharm配置好环境的终端下运行以下代码(自行修改路径):
python demo.py -cfgfile E:\ZZZcoda\Cyolo.coda\v4\cfg\yolov4.cfg -weightfile E:\ZZZcoda\Cyolo.coda\v4\weight\yolov4.weights -imgfile E:\ZZZcoda\Cyolo.coda\v4\data\dog.jpg
1.会出现第一个报错提醒:NameError: name 'false' is not defined
Traceback (most recent call last):
File "E:\ZZZcoda\Cyolo.coda\v4\demo.py", line 159, in <module>
args = get_args()
File "E:\ZZZcoda\Cyolo.coda\v4\demo.py", line 151, in get_args
parser.add_argument('-torch', type=bool, default=false,
NameError: name 'false' is not defined
问题的原因是源代码中的:false应该将F大写
如果跟我一样,不想修改源代码,在你的代码(自行修改路径)后面加上:-torch False
python demo.py -cfgfile E:\ZZZcoda\Cyolo.coda\v4\cfg\yolov4.cfg -weightfile E:\ZZZcoda\Cyolo.coda\v4\weight\yolov4.weights -imgfile E:\ZZZcoda\Cyolo.coda\v4\data\dog.jpg -torch False
第一个问题就可以解决了。
【如果你习惯修改源代码的话,打开demo.py,找到
parser.add_argument('-torch', type=bool, default=false, help='use torch weights')
将这里的false改为False即可解决】
2.如果你在这个环境下运行过其他版本的YOLO,可能会出现第二个报错提醒:> Overload resolution failed:
> - Can't parse 'pt2'. Sequence item with index 0 has a wrong type
> - Can't parse 'pt2'. Sequence item with index 0 has a wrong type
> - Can't parse 'rec'. Expected sequence length 4, got 2
> - Can't parse 'rec'. Expected sequence length 4, got 2
> Overload resolution failed:
> - Can't parse 'pt2'. Sequence item with index 0 has a wrong type
> - Can't parse 'pt2'. Sequence item with index 0 has a wrong type
> - Can't parse 'rec'. Expected sequence length 4, got 2
> - Can't parse 'rec'. Expected sequence length 4, got 2
问题的原因是:opencv-python版本不对
分别运行如下代码:
pip show opencv_python #展示自己opencv_python的版本
pip uninstall opencv-python #卸载之前的版本
pip install opencv_python==4.4.0.46 #下载4.4.0.46这个版本
第二个问题也就解决了,再次运行:
python demo.py -cfgfile E:\ZZZcoda\Cyolo.coda\v4\cfg\yolov4.cfg -weightfile E:\ZZZcoda\Cyolo.coda\v4\weight\yolov4.weights -imgfile E:\ZZZcoda\Cyolo.coda\v4\data\dog.jpg -torch False
弹出如下信息表示模型测试完成,
E:\ZZZcoda\Cyolo.coda\v4\data\dog.jpg: Predicted in 0.081639 seconds.
bicycle: 0.923744
truck: 0.917914
dog: 0.979061
save plot results to predictions.jpg
预测结果图如下图。