用matplotlib画PR曲线

首先,头文件加入:

import matplotlib as plt

然后以VOC为例,画PR曲线:

def _do_python_eval(self, output_dir='output'):
        #rootpath = os.path.join(self.root, 'VOC' + self._year)
        rootpath = '/data/Datasets/luzs/PCB/pcb_final_test'
        name = self.image_set[0][1]
        annopath = os.path.join(
            rootpath,
            'Annotations',
            '{:s}.xml')
        #imagesetfile = os.path.join(
        #    rootpath,
        #    'ImageSets',
        #    'Main',
        #    name + '.txt')
        imagesetfile = self.txt_dir
        cachedir = os.path.join(self.root, 'annotations_cache')
        aps = []
        # The PASCAL VOC metric changed in 2010
        use_07_metric = True if int(self._year) < 2010 else False
        print('VOC07 metric? ' + ('Yes' if use_07_metric else 'No'))
        if output_dir is not None and not os.path.isdir(output_dir):
            os.mkdir(output_dir)
        for i, cls in enumerate(VOC_CLASSES):
            if cls == '__background__':
                continue
            filename = self._get_voc_results_file_template().format(cls)
            rec, prec, ap = voc_eval(
                filename, annopath, imagesetfile, cls, cachedir, ovthresh=0.5,
                use_07_metric=use_07_metric)
            aps += [ap]
            plt.plot(rec, prec, lw=2, label = 'PR curve of class {}(area={:.4f})'.format(cls,ap))
            print('AP for {} = {:.4f}'.format(cls, ap))
            if output_dir is not None:
                with open(os.path.join(output_dir, cls + '_pr.pkl'), 'wb') as f:
                    pickle.dump({'rec': rec, 'prec': prec, 'ap': ap}, f)
        plt.xlabel('Recall')    
        plt.ylabel('Precision')    
        plt.grid(True)    
        plt.ylim([0.0, 1.05])    
        plt.xlim([0.0, 1.0])    
        plt.title('Precision-Recall')    
        plt.legend(loc="bottom left")         
        plt.savefig('pr.jpg')

最主要的都是plt开头的那几行。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值