eval_pr_curve.py
def plot_pr_curve_multi(config_file_list, result_file_list, lenged_label_list, category_index=0, metric="bbox"):
    """plot precison-recall curve based on testing results of pkl file.

        Args:
            config_file_list (list[list | tuple]): config file path.
            result_file_list (str): pkl file of testing results path.
            metric (str): Metrics to be evaluated. Options are
                'bbox', 'segm'.
    """
    pr_data_list = []
    curve_num = len(result_file_list)

    for (config_file, result_file) in zip(config_file_list, result_file_list):

        cfg = Config.fromfile(config_file)
        # turn on test mode of dataset
        if isinstance(cfg.data.test, dict):
            cfg.data.test.test_mode = True
        elif isinstance(cfg.data.test, list):
            for ds_cfg in cfg.data.test:
                ds_cfg.test_mode = True

        # build dataset
        dataset = build_dataset(cfg.data.test)
        # load result file in pkl format
        pkl_results = mmcv.load(result_file)
        # convert pkl file (list[list | tuple | ndarray]) to json
        json_results, _ = dataset.format_results(pkl_results)
        # initialize COCO instance
        coco = COCO(annotation_file=cfg.data.test.ann_file)
        coco_gt = coco
        coco_dt = coco_gt.loadRes(json_results[metric]) 
        # initialize COCOeval instance
        coco_eval = COCOeval(coco_gt, coco_dt, metric)
        coco_eval.evaluate()
        coco_eval.accumulate()
        coco_eval.summarize()
        # extract eval data
        precisions = coco_eval.eval["precision"]
        '''
        precisions[T, R, K, A, M]
        T: iou thresholds [0.5 : 0.05 : 0.95], idx from 0 to 9
        R: recall thresholds [0 : 0.01 : 1], idx from 0 to 100
        K: category, idx from 0 to ...
        A: area range, (all, small, medium, large), idx from 0 to 3 
        M: max dets, (1, 10, 100), idx from 0 to 2
        '''
        pr_data50 = precisions[0, :, category_index, 0, 2] 
        pr_data55 = precisions[1, :, category_index, 0, 2] 
        pr_data60 = precisions[2, :, category_index, 0, 2] 
        pr_data65 = precisions[3, :, category_index, 0, 2] 
        pr_data70 = precisions[4, :, category_index, 0, 2] 
        pr_data75 = precisions[5, :, category_index, 0, 2] 
        pr_data80 = precisions[6, :, category_index, 0, 2] 
        pr_data85 = precisions[7, :, category_index, 0, 2] 
        pr_data90 = precisions[8, :, category_index, 0, 2] 
        pr_data95 = precisions[9, :, category_index, 0, 2] 

        
        # store pr_data
        pr_data_list.append(pr_data75)

    # plot
    x = np.arange(0.0, 1.01, 0.01)
    for (pr_data, label_name) in zip(pr_data_list, lenged_label_list):
        plt.plot(x, pr_data, label=label_name)

    plt.xlabel("recall")
    plt.ylabel("precison")
    plt.xlim(0, 1.0)
    plt.ylim(0, 1.01)
    plt.grid(True)
    plt.legend(fontsize=8, loc="lower left")
    # plt.legend(fontsize=10)
    plt.show()
plot precison-recall curve based on testing results of pkl file.

        Args:
            config_file_list (list[list | tuple]): config file path.
            result_file_list (str): pkl file of testing results path.
            metric (str): Metrics to be evaluated. Options are
                'bbox', 'segm'.
    
plot precison-recall curve based on testing results of pkl file.
plot precison - recall curve based on testing results of pkl file .
def plot_pr_curve_multi(config_file_list, result_file_list, lenged_label_list, category_index=0, metric="bbox"):
    pr_data_list = []
    curve_num = len(result_file_list)
    for (config_file, result_file) in zip(config_file_list, result_file_list):
        cfg = Config.fromfile(config_file)
        if isinstance(cfg.data.test, dict):
            cfg.data.test.test_mode = True
        elif isinstance(cfg.data.test, list):
            for ds_cfg in cfg.data.test:
                ds_cfg.test_mode = True
        dataset = build_dataset(cfg.data.test)
        pkl_results = mmcv.load(result_file)
        json_results, _ = dataset.format_results(pkl_results)
        coco = COCO(annotation_file=cfg.data.test.ann_file)
        coco_gt = coco
        coco_dt = coco_gt.loadRes(json_results[metric]) 
        coco_eval = COCOeval(coco_gt, coco_dt, metric)
        coco_eval.evaluate()
        coco_eval.accumulate()
        coco_eval.summarize()
        precisions = coco_eval.eval["precision"]
        pr_data50 = precisions[0, :, category_index, 0, 2] 
        pr_data55 = precisions[1, :, category_index, 0, 2] 
        pr_data60 = precisions[2, :, category_index, 0, 2] 
        pr_data65 = precisions[3, :, category_index, 0, 2] 
        pr_data70 = precisions[4, :, category_index, 0, 2] 
        pr_data75 = precisions[5, :, category_index, 0, 2] 
        pr_data80 = precisions[6, :, category_index, 0, 2] 
        pr_data85 = precisions[7, :, category_index, 0, 2] 
        pr_data90 = precisions[8, :, category_index, 0, 2] 
        pr_data95 = precisions[9, :, category_index, 0, 2] 
        pr_data_list.append(pr_data75)
    x = np.arange(0.0, 1.01, 0.01)
    for (pr_data, label_name) in zip(pr_data_list, lenged_label_list):
        plt.plot(x, pr_data, label=label_name)
    plt.xlabel("recall")
    plt.ylabel("precison")
    plt.xlim(0, 1.0)
    plt.ylim(0, 1.01)
    plt.grid(True)
    plt.legend(fontsize=8, loc="lower left")
    plt.show()
def plot_pr_curve_multi ( config_file_list , result_file_list , lenged_label_list , category_index = 0 , metric = "bbox" ) : pr_data_list = [ ] curve_num = len ( result_file_list ) for ( config_file , result_file ) in zip ( config_file_list , result_file_list ) : cfg = Config . fromfile ( config_file ) if isinstance ( cfg . data . test , dict ) : cfg . data . test . test_mode = True elif isinstance ( cfg . data . test , list ) : for ds_cfg in cfg . data . test : ds_cfg . test_mode = True dataset = build_dataset ( cfg . data . test ) pkl_results = mmcv . load ( result_file ) json_results , _ = dataset . format_results ( pkl_results ) coco = COCO ( annotation_file = cfg . data . test . ann_file ) coco_gt = coco coco_dt = coco_gt . loadRes ( json_results [ metric ] ) coco_eval = COCOeval ( coco_gt , coco_dt , metric ) coco_eval . evaluate ( ) coco_eval . accumulate ( ) coco_eval . summarize ( ) precisions = coco_eval . eval [ "precision" ] '''
        precisions[T, R, K, A, M]
        T: iou thresholds [0.5 : 0.05 : 0.95], idx from 0 to 9
        R: recall thresholds [0 : 0.01 : 1], idx from 0 to 100
        K: category, idx from 0 to ...
        A: area range, (all, small, medium, large), idx from 0 to 3 
        M: max dets, (1, 10, 100), idx from 0 to 2
        ''' pr_data50 = precisions [ 0 , : , category_index , 0 , 2 ] pr_data55 = precisions [ 1 , : , category_index , 0 , 2 ] pr_data60 = precisions [ 2 , : , category_index , 0 , 2 ] pr_data65 = precisions [ 3 , : , category_index , 0 , 2 ] pr_data70 = precisions [ 4 , : , category_index , 0 , 2 ] pr_data75 = precisions [ 5 , : , category_index , 0 , 2 ] pr_data80 = precisions [ 6 , : , category_index , 0 , 2 ] pr_data85 = precisions [ 7 , : , category_index , 0 , 2 ] pr_data90 = precisions [ 8 , : , category_index , 0 , 2 ] pr_data95 = precisions [ 9 , : , category_index , 0 , 2 ] pr_data_list . append ( pr_data75 ) x = np . arange ( 0.0 , 1.01 , 0.01 ) for ( pr_data , label_name ) in zip ( pr_data_list , lenged_label_list ) : plt . plot ( x , pr_data , label = label_name ) plt . xlabel ( "recall" ) plt . ylabel ( "precison" ) plt . xlim ( 0 , 1.0 ) plt . ylim ( 0 , 1.01 ) plt . grid ( True ) plt . legend ( fontsize = 8 , loc = "lower left" ) plt . show ( )
plot precison-recall curve based on testing results of pkl file.
plot precison - recall curve based on testing results of pkl file .
"""plot precison-recall curve based on testing results of pkl file.

        Args:
            config_file_list (list[list | tuple]): config file path.
            result_file_list (str): pkl file of testing results path.
            metric (str): Metrics to be evaluated. Options are
                'bbox', 'segm'.
    """ # turn on test mode of dataset # build dataset # load result file in pkl format # convert pkl file (list[list | tuple | ndarray]) to json # initialize COCO instance # initialize COCOeval instance # extract eval data '''
        precisions[T, R, K, A, M]
        T: iou thresholds [0.5 : 0.05 : 0.95], idx from 0 to 9
        R: recall thresholds [0 : 0.01 : 1], idx from 0 to 100
        K: category, idx from 0 to ...
        A: area range, (all, small, medium, large), idx from 0 to 3 
        M: max dets, (1, 10, 100), idx from 0 to 2
        ''' # store pr_data # plot # plt.legend(fontsize=10)
config_file_list
config file path.
config file path .
result_file_list
pkl file of testing results path.
pkl file of testing results path .
lenged_label_list
category_index
metric
Metrics to be evaluated. Options are
'bbox', 'segm'.
Metrics to be evaluated . Options are ' bbox ' ' segm ' .