用caffe训练生成的log文件画mAP

虽说caffe自带了处理log画loss等的函数,不过用着不舒服,而且对于SSD这样自己定义的一些loss层,不适用。
用SSD训练完,每次都要去看detection_eval也就是mAP。对不同的参数还要对比,不如写一个函数画出来对比好了,比较直观。

import os
import argparse
import re
import math

import matplotlib.pyplot as plt

def parse_args():
    args = argparse.ArgumentParser()
    args.add_argument('logs',nargs='+')
    return args.parse_args()

def get_detection_eval(logfile):
    test_iteration = re.compile(r'Iteration \d+, Testing net \(#0\)')
    test_iter = re.compile(r'\d+')

    regex_detection_eval = re.compile(r'cls_[aA]cc = \d\.\d+')
    regex_num = re.compile(r'\d\.\d+')

    detection_eval = []
    iteration = []
    with open(logfile) as f:
        for line in f:
            test = test_iteration.findall(line)
            detection = regex_detection_eval.findall(line)
            if test:
                test_num = test_iter.findall(test[0])
                iteration.append(int(test_num[0])/1000)
            if detection:
                acc = regex_num.findall(detection[0])
                detection_eval.append(float(acc[0]))
    return iteration, detection_eval


def draw_plot(logs):
    for log in logs:
        iteration, detection_eval = get_detection_eval(log)
        print len(detection_eval)
        plt.plot(iteration, detection_eval, label=log.split('\\')[-1][:-4])
        detection_eval_sorted = sorted(detection_eval, reverse=True)
        print log.split('\\')[-1][:-4],"max: ",detection_eval_sorted[:3]
    plt.legend(loc='upper left')
    plt.show()

if __name__ == "__main__":
    args = parse_args()
    draw_plot(args.logs)
    print args

猜你喜欢

转载自blog.csdn.net/u012420309/article/details/78933982