Faster R-CNN画PR曲线

参考:https://github.com/rbgirshick/py-faster-rcnn/issues/670

原地址https://blog.csdn.net/hongxingabc/article/details/80064574

在pascal_voc.py里添加几行代码即可:

1,文件头部:

 

  1. import matplotlib.pyplot as plt

  2. import pylab as pl

  3. from sklearn.metrics import precision_recall_curve

  4. from itertools import cycle

2,_do_python_eval函数:
def _do_python_eval(self, output_dir='output'):

  1. annopath = os.path.join(

  2. self._devkit_path,

  3. 'VOC' + self._year,

  4. 'Annotations',

  5. '{:s}.xml')

  6. imagesetfile = os.path.join(

  7. self._devkit_path,

  8. 'VOC' + self._year,

  9. 'ImageSets',

  10. 'Main',

  11. self._image_set + '.txt')

  12. cachedir = os.path.join(self._devkit_path, 'annotations_cache')

  13. aps = []

  14. # The PASCAL VOC metric changed in 2010

  15. use_07_metric = True if int(self._year) < 2010 else False

  16. print('VOC07 metric? ' + ('Yes' if use_07_metric else 'No'))

  17. if not os.path.isdir(output_dir):

  18. os.mkdir(output_dir)

  19. for i, cls in enumerate(self._classes):

  20. if cls == '__background__':

  21. continue

  22. filename = self._get_voc_results_file_template().format(cls)

  23. rec, prec, ap = voc_eval(

  24. filename, annopath, imagesetfile, cls, cachedir, ovthresh=0.5,

  25. use_07_metric=use_07_metric)

  26. aps += [ap]

  27. pl.plot(rec, prec, lw=2,

  28. label='Precision-recall curve of class {} (area = {:.4f})'

  29. ''.format(cls, ap))

  30. print(('AP for {} = {:.4f}'.format(cls, ap)))

  31. with open(os.path.join(output_dir, cls + '_pr.pkl'), 'wb') as f:

  32. pickle.dump({'rec': rec, 'prec': prec, 'ap': ap}, f)

  33.  
  34. pl.xlabel('Recall')

  35. pl.ylabel('Precision')

  36. plt.grid(True)

  37. pl.ylim([0.0, 1.05])

  38. pl.xlim([0.0, 1.0])

  39. pl.title('Precision-Recall')

  40. pl.legend(loc="upper right")

  41. plt.show()

  42.  
  43. print(('Mean AP = {:.4f}'.format(np.mean(aps))))

  44. print('~~~~~~~~')

  45. print('Results:')

  46. for ap in aps:

  47. print(('{:.3f}'.format(ap)))

  48. print(('{:.3f}'.format(np.mean(aps))))

  49. print('~~~~~~~~')

  50. print('')

  51. print('--------------------------------------------------------------')

  52. print('Results computed with the **unofficial** Python eval code.')

  53. print('Results should be very close to the official MATLAB eval code.')

  54. print('Recompute with `./tools/reval.py --matlab ...` for your paper.')

  55. print('-- Thanks, The Management')

  56. print('--------------------------------------------------------------')

然后运行test_net.py,就可以得到如下图的PR曲线。如果想比较多条曲线,可以先把rec, prec数据存起来再画图。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值