赞
踩
训练完模型之后,当然是可视化看看情况如何,这里先声明环境:Ubuntu 16.04、darknet53
好,那我们来看这几个指标的可视化吧~
这两个指标是和训练过程结合在一起的,具体的绘制参考博客:
https://blog.csdn.net/qq_34806812/article/details/81459982
感谢这位作者,非常的详细~
如果你对这两个概念很是模糊的话,建议先阅读下我之前这篇博客:
https://blog.csdn.net/m0_37970224/article/details/89352357
试着计算一下,很通俗易懂了~
这里默认你已经会valid了,有生成results文件了,不会的看:
https://blog.csdn.net/amusi1994/article/details/81564504
网上查的绘制P-R曲线,计算mAP值全是用voc_eval.py来做,那么问题来了:
重点:
我之前标注文件是json格式文件,并没有xml格式的标注文件(因为我也没有转过去),遇到这种情况怎么破?
答案:
弄懂voc_eval.py,并改造~
网上也有voc_eval.py的详解,但是有些地方不够清楚,这就很纳闷
参考博客:https://blog.csdn.net/gusui7202/article/details/83930430#commentBox
这里需要说下几个点:
文中代码143行:
npos = npos + sum(~difficult)
有人说因为difficult都为0,所以sum(~difficult)也为0,
显然它没看上一行:
difficult = np.array([x['difficult'] for x in R]).astype(np.bool)
这个得出的是[False False]的形式,你print一下就知道了~
还有一点我先说,就是正负样本的确定,是以IOU>0.5为界定,大于0.5就是正,小于就是负咯,体现在代码的:
//这里比较不好理解,我也没理解,作者里面好像有补充了下
if ovmax > ovthresh:
if not R['difficult'][jmax]:
if not R['det'][jmax]:
tp[d] = 1.
R['det'][jmax] = 1
else:
fp[d] = 1.
else:
fp[d] = 1.
说了这么多,都是在阅读源码,现在来改造吧~
//这个是原voc_eval.py def parse_rec(filename): """ Parse a PASCAL VOC xml file """ tree = ET.parse(filename) objects = [] for obj in tree.findall('object'): obj_struct = {} obj_struct['name'] = obj.find('name').text obj_struct['pose'] = obj.find('pose').text obj_struct['truncated'] = int(obj.find('truncated').text) obj_struct['difficult'] = int(obj.find('difficult').text) bbox = obj.find('bndbox') obj_struct['bbox'] = [int(bbox.find('xmin').text), int(bbox.find('ymin').text), int(bbox.find('xmax').text), int(bbox.find('ymax').text)] objects.append(obj_struct) return objects //改成读取json的,这里的话主要两个重要信息name(类别)和 bbox(坐标),其他的没用 //修改后 # 读取json数据 filedir = 'E:\data\TT100K_TRAIN\/test\yolo\data_45.json' annos = json.loads(open(filedir).read()) def parse_rec(filename): objects = [] # print(annos) for obj in annos['imgs'][filename]['objects']: obj_struct = {} bbox = obj['bbox'] obj_struct['name'] = obj['category'] obj_struct['bbox'] = [int(bbox['xmin']), int(bbox['ymin']), int(bbox['xmax']), int(bbox['ymax'])] objects.append(obj_struct) return objects
voc_eval这个方法就改了两个地方 一个是difficult: 原来: difficult = np.array([x['difficult'] for x in R]).astype(np.bool) 因为我们没有x['difficult'],就可以当作都是0来处理 修改为: difficult = np.zeros(len(R)).astype(np.bool) 另一个是去掉函数的第二个参数annopath,因为我们没有xml标注文件 def voc_eval(detpath, annopath, imagesetfile, classname, cachedir, ovthresh=0.5, use_07_metric=False): 然后 82行:recs[imagename] = parse_rec(annopath.format(imagename)) 修改为: recs[imagename] = parse_rec(imagename) 还有:with open(cachefile, 'wb') as f:wb没加b会报错,r也是换成rb
对,还有个绘制
//compute_mAP.py from eval_if_not_xml import eval_if_not_xml import matplotlib.pyplot as plt from matplotlib.pyplot import MultipleLocator # rec, prec, ap = voc_eval('./results/{}.txt', 'E:\data\VOCdevkit\VOC2007\Annotations\{}.xml', 'D:\deep\YOLO3\可视化\/visualization\/file\/test.txt', 'person', '.') rec, prec, ap = eval_if_not_xml('./results/{}.txt', 'E:\data\TT100K_TRAIN\/test\yolo/ids.txt', 'i2', '.') x = rec y = prec plt.figure() plt.xlabel('recall') plt.ylabel('precision') plt.title('PR cruve') x_major_locator = MultipleLocator(0.1) y_major_locator = MultipleLocator(0.1) plt.plot(x, y) plt.show() print('rec', rec) print('prec', prec) print('ap', ap)
结果:
控制台:
rec [0.003367 0.00673401 0.01010101 0.01346801 0.01683502 0.02020202 0.02356902 0.02693603 0.03030303 0.03367003 0.03703704 0.04040404 0.04377104 0.04713805 0.05050505 0.05387205 0.05723906 0.06060606 0.06397306 0.06734007 0.07070707 0.07407407 0.07744108 0.08080808 0.08417508 0.08754209 0.09090909 0.09427609 0.0976431 0.1010101 0.1043771 0.10774411 0.11111111 0.11447811 0.11784512 0.12121212 0.12457912 0.12794613 0.13131313 0.13468013 0.13804714 0.14141414 0.14478114 0.14814815 0.15151515 0.15488215 0.15824916 0.16161616 0.16498316 0.16835017 0.17171717 0.17508418 0.17845118 0.18181818 0.18518519 0.18855219 0.19191919 0.1952862 0.1986532 0.2020202 0.20538721 0.20875421 0.21212121 0.21548822 0.21885522 0.22222222 0.22558923 0.22895623 0.23232323 0.23569024 0.23905724 0.24242424 0.24579125 0.24915825 0.25252525 0.25589226 0.25925926 0.26262626 0.26599327 0.26936027 0.27272727 0.27609428 0.27946128 0.28282828 0.28619529 0.28956229 0.29292929 0.2962963 0.2996633 0.3030303... ========================================================================== prec [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0.99115044 0.99122807 0.99130435 0.99137931 0.99145299 0.99152542 0.98319328 0.98333333... ============================================================================ ap 0.9323720885916942 //其实可以对照的计算一下加深理解(前提是你了解P-R、mAP是啥子) 建议阅读:https://blog.csdn.net/m0_37970224/article/details/89352357 并计算! mAP的话就是各类别ap的平均
Recall 参考:
https://blog.csdn.net/xue_csdn/article/details/94765810
的recall部分
有其他的后续补充吧~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。