示例#1
0
def get_acc_pre_rec(model, points=100):
    acc_list = []
    threshold_list = []
    precision_list = []
    recall_list = []
    for SCORE_THRESHOLD in tqdm.tqdm(range(1, points)):
        ts.test(model, SCORE_THRESHOLD / points)
        main_map.get_map()
        threshold_list.append(float(SCORE_THRESHOLD / points))
        # 得到#号的行
        with open(results_path, 'r') as results_f:
            results_data = results_f.readlines()
            indexes = []
            for i, line in enumerate(results_data):
                if line.find('#') > -1:
                    indexes.append(i)

        #统计gt的个数
        gt_obj_name_all = {}
        for i in range(len(results_data)):
            if i > indexes[2] and i < (indexes[3] - 1):
                d = results_data[i].strip().replace(' ', '').split(':')
                gt_obj_name_all[d[0]] = int(d[1])

            if i >= indexes[3]: break

        gt_num_list = list(gt_obj_name_all.values())
        gt_num = np.sum(gt_num_list)

        # print('测试集中的所有样本数据:', obj_name_all)
        # 读取fp,fp;计算R-P值
        predict_correct = 0
        predict_sum = 0
        for d in results_data:
            if d.find('tp') > -1:
                d_ = d.strip().replace(' ', '').replace('(', '#').replace(
                    ',', '#').replace(')', '').split('#')
                d_0 = d_[0].split(':')
                d_1 = d_[1].split(':')
                predict_sum += int(d_0[1])
                predict_correct += int(d_1[1])

        acc = float(predict_correct / gt_num)
        precision = float(predict_correct / predict_sum)
        recall = float(predict_correct / gt_num)
        acc_list.append(acc)
        precision_list.append(precision)
        recall_list.append(recall)

    return threshold_list, acc_list, precision_list, recall_list
示例#2
0
 def on_epoch_end(self, epoch, logs={}):
     self.count_epochs += 1
     if self.count_epochs % 5 == 0:
         test(self.model, 0.3, draw_boxes=False)
         mAp = main_map.get_map()
         print(mAp)
         self.mAP_list.append(mAp)
         with open(self.map_list_save_path, 'wb') as map_f:
             pickle.dump(self.mAP_list, map_f)
示例#3
0
    plt.ylabel('Recall')
    plt.axis([0, 1, 0, 1])
    plt.plot(threshold_list, recall_list, 'r-')
    plt.savefig(pre_fig_path)


if __name__ == '__main__':
    create = True
    if create:
        model = create_model()
        weights_path = os.path.join(CurDir, 'model', "yolov3.weights")
        model.load_weights(weights_path)
        model.summary()
        ts.test(model, 0.3, draw_boxes=False)

    print(get_map())
    plot_class_precision()
    '''
    plot_map()
    plot_train_loss()
    plot_test_loss()
    ts.test(model, 0.3, draw_boxes=True)
    print(get_map())
    plot_class_precision()
    sumpr()

    threshold_list, acc_list, precision_list, recall_list = get_acc_pre_rec(model, points=10)
    plot_acc(threshold_list, acc_list)
    plot_precision(threshold_list, precision_list)
    plot_recall(threshold_list, recall_list)
    '''