Exemple #1
0
def plot_sort_h264():
    tex.setup(width=2, l=0.1, r=0.9, b=0.1, t=0.9)
    methods = ['lum', 'glcm', 'random']
    crfs = [25, 20]
    x = np.arange(3)
    accu_lum = np.array([17.2, 21.4]) / 23.3 * 100
    accu_glcm = np.array([17.4, 21.4]) / 23.3 * 100
    accu_random = np.array([17.3, 21.5]) / 23.3 * 100
    baseline_jpg = parse_logfile('./logs_pedes/resized_size.log', 0)
    base = './logs_pedes/log_h264_sort_{}_crf_{}.log'
    ratios = {'lum':[], 'glcm':[], 'random':[]}
    ratios_err = {'lum':[], 'glcm':[], 'random':[]}
    for method in methods:
        for crf in crfs:
            data = parse_logfile(base.format(method, crf), 2, False)
            data_jpg = np.array(data) / baseline_jpg * 100
            jpg_mean, jpg_err = calc_ci(data_jpg)
            ratios[method].append(jpg_mean)
            ratios_err[method].append(jpg_err)

    fig = plt.figure()
    plt.errorbar(accu_lum, ratios['lum'], yerr=ratios_err['lum'], 
                 color='g', capsize=2)
    plt.errorbar(accu_glcm, ratios['glcm'], yerr=ratios_err['glcm'], 
                color='b', capsize=2)
    plt.errorbar(accu_random, ratios['random'], yerr=ratios_err['random'], 
                 color='r', capsize=2)
    plt.legend(('lum', 'glcm', 'random'))
    plt.xlabel('Average precision(\%)')
    plt.ylabel('Size of compressed feature maps/Size of original feature maps(\%)')
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\h264_sort_methods.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #2
0
def plot_intra_ratio_ap():
    tex.setup(width=2, l=0.1, r=0.9, b=0.1, t=0.9)
    def get_plot_data(method):
        baseline_raw = 608 * 608 * 3
        baseline_jpg = parse_logfile('./logs_pedes/resized_size.log', 0)
        if method == 'jpeg':
            base = './logs_pedes/log_jpeg_q_{}.log'
        if method == 'webp':
            base = './logs_pedes/log_webp_q_{}.log'

        qs = np.arange(20, 100, 10)
        ratios_raw = []
        ratios_jpg = []
        err_raw = []
        err_jpg = []
        for q in qs:
            # if webp, then False
            data = parse_logfile(base.format(q), 2, False)
            data_raw = np.array(data) / baseline_raw * 100
            data_jpg = np.array(data) / baseline_jpg * 100
            raw_mean, raw_err = calc_ci(data_raw)
            jpg_mean, jpg_err = calc_ci(data_jpg)
            ratios_raw.append(raw_mean)
            ratios_jpg.append(jpg_mean)
            err_raw.append(raw_err)
            err_jpg.append(jpg_err)
        return ratios_raw, ratios_jpg, err_raw, err_jpg
    ratios_raw_jpeg, ratios_jpg_jpeg, err_raw_jpeg, err_jpg_jpeg = get_plot_data(
        'jpeg')
    ratios_raw_webp, ratios_jpg_webp, err_raw_webp, err_jpg_webp = get_plot_data(
        'webp')
    # jpg_ratio = [7.70, 5.21, 4.07, 3.35, 2.80, 2.23, 1.68, 1.10]
    jpg_accu = np.array([13.9, 18.8, 21.0, 22.1, 22.6,
                         23.0, 23.2, 23.2]) / 23.3 * 100

    # webp_ratio = [7.01, 5.04, 3.97, 3.30, 2.83, 2.44, 1.86, 1.20]
    webp_accu = np.array([19.0, 21.4, 22.4, 22.8, 23.0,
                          23.0, 23.2, 23.3]) / 23.3 * 100
    # x = np.arange(13, 25, 1)
    plt.figure()
    plt.errorbar(jpg_accu, ratios_raw_jpeg,
                 yerr=err_raw_jpeg, color='b', capsize=4)
    plt.errorbar(webp_accu, ratios_raw_webp, yerr=err_raw_webp,
                 color='darkblue', fmt='--', capsize=4)
    plt.errorbar(jpg_accu, ratios_jpg_jpeg,
                 yerr=err_jpg_jpeg, color='g', capsize=4)
    plt.errorbar(webp_accu, ratios_jpg_webp, yerr=err_jpg_webp,
                 color='darkgreen', fmt='--', capsize=4)
    # plt.xticks(x)
    # plt.scatter(jpg_accu, ratios_raw_jpeg, marker='o', linewidths=1)
    # plt.scatter(webp_accu, webp_ratio, marker='v', linewidths=1)
    plt.xlabel('Average Precision(\%)')
    plt.ylabel('Size of compressed image/Size of original image(\%)')
    plt.legend(('JPEG of Raw Input.', 'WEBP of Raw Input.',
                'JPEG of JPEG Input.', 'WEBP of JPEG Input.'))
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\intra_ratio_accu.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #3
0
def plot_ratio_quality():

    x = np.arange(20, 100, 10)
    # jpg_ratio = [7.70, 5.21, 4.07, 3.35, 2.80, 2.23, 1.68, 1.10]
    # webp_ratio = [7.01, 5.04, 3.97, 3.30, 2.83, 2.44, 1.86, 1.20]
    tex.setup(width=1, l=0.15, r=0.9, b=0.15, t=0.9)
    def get_plot_data(method):
        baseline_raw = 608 * 608 * 3
        baseline_jpg = parse_logfile('./logs_pedes/resized_size.log', 0)
        if method == 'jpeg':
            base = './logs_pedes/log_jpeg_q_{}.log'
        if method == 'webp':
            base = './logs_pedes/log_webp_q_{}.log'

        qs = np.arange(20, 100, 10)
        ratios_raw = []
        ratios_jpg = []
        err_raw = []
        err_jpg = []
        for q in qs:
            # if webp, then False
            data = parse_logfile(base.format(q), 2, False)
            data_raw = np.array(data) / baseline_raw * 100
            data_jpg = np.array(data) / baseline_jpg * 100
            raw_mean, raw_err = calc_ci(data_raw)
            jpg_mean, jpg_err = calc_ci(data_jpg)
            ratios_raw.append(raw_mean)
            ratios_jpg.append(jpg_mean)
            err_raw.append(raw_err)
            err_jpg.append(jpg_err)
        return ratios_raw, ratios_jpg, err_raw, err_jpg

    ratios_raw_jpeg, ratios_jpg_jpeg, err_raw_jpeg, err_jpg_jpeg = get_plot_data(
        'jpeg')
    ratios_raw_webp, ratios_jpg_webp, err_raw_webp, err_jpg_webp = get_plot_data(
        'webp')

    fig = plt.figure()

    plt.errorbar(x+0.25, ratios_raw_jpeg,
                 yerr=err_raw_jpeg, color='b', capsize=4)
    plt.errorbar(x-0.25, ratios_raw_webp, yerr=err_raw_webp,
                 fmt='--', color='darkblue', capsize=4)

    plt.errorbar(x+0.25, ratios_jpg_jpeg,
                 yerr=err_jpg_jpeg, color='g', capsize=4)
    plt.errorbar(x-0.25, ratios_jpg_webp, yerr=err_jpg_webp,
                 color='darkgreen', fmt='--', capsize=4)

    plt.xlabel('Quality')
    plt.ylabel('Compressed size/Original size(\%)')
    plt.legend(('JPEG of Raw Input.', 'WEBP of Raw Input.',
                'JPEG of JPEG Input.', 'WEBP of JPEG Input.'))
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\ratio_quality_comp.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #4
0
def plot_data_based_all(input_data='jpg'):
    """
    base: 'jpg' for JPEG Input
          'raw' for Raw Input
    """
    tex.setup(width=2, l=0.1, r=0.9, b=0.1, t=0.9)
    baseline_raw = 608 * 608 * 3
    baseline_jpg = parse_logfile('./logs_pedes/resized_size.log', 0)
    ap = np.array([23.3, 23.3, 23.3, 22.9, 22.9]) / 23.3 * 100
    xnames = ['zlib', '1 decimal','NormedCut+zlib', 'Cut+zlib', 'Cut+PNG']
    x = np.arange(5)
    base = './logs_pedes/'
    files = ['log_float_decimals_10.log', 'log_float_decimals_1.log', 
        'log_cut_norm.log','log_cut_orig.log', 'log_png.log']
    baseline = [baseline_jpg, baseline_raw]
    flag = 0 if input_data == 'jpg' else 1
    ratio = []
    ratio_err = []
    for f in files:
        f_name = base + f
        data = open(f_name).readlines()
        ratios = np.array([int(i.split()[2]) for i in data]) / baseline[flag] * 100
        mean, err = calc_ci(ratios)
        ratio.append(mean)
        ratio_err.append(err)

    fig, ax1 = plt.subplots()
    color1 = 'darkblue'
    ax1.set_xlabel('Approaches for Feature Maps Compressibility Evaluation')
    ax1.set_ylabel('Average Precision(\%)', color=color1)
    l1 = ax1.scatter(x , ap, color=color1)
    ax1.plot(x, ap, color=color1)
    for a, b in zip(x, np.round(ap, 1)):
        ax1.text(a, b + 0.2, str(b), color=color1)
    ax1.tick_params(axis='y', labelcolor=color1)
    plt.ylim(90, 102)
    ax2 = ax1.twinx()
    ax2.set_ylabel('Compressed size/Original size(\%)', color='k')
    l2 = ax2.bar(x, ratio, yerr=ratio_err, width=0.2, capsize=2, align='center',
                 color='#f33c74', hatch='x')
    for a, b in zip(x, np.round(ratio, 1)):
        ax2.text(a + 0.05, b + 4, str(b))
    ax2.tick_params(axis='y', labelcolor='k')
    if input_data == 'raw':
        plt.ylim(0, 200)
    else:
        pass
    plt.xticks(x, xnames)
    ax2.legend([l1, l2], ('Average Precision', 'Compression Performance'))
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\data_based_approached_{}.pdf'.format(input_data),
                format='pdf', dpi=1000)
    plt.show()
Exemple #5
0
def plot_png_zlib():
    tex.setup(width=2, l=0.1, r=0.9, b=0.1, t=0.9)
    zlib_data_path = './logs_pedes/log_cut_orig.log'
    png_data_path = './logs_pedes/log_png.log'
    baseline_jpg = parse_logfile('./logs_pedes/resized_size.log', 0)
    baseline_raw = 608 * 608 * 3

    x = np.arange(2)
    x_names = ['PNG', 'zlib']

    png_size = parse_logfile(png_data_path, 2)
    zlib_size = parse_logfile(zlib_data_path, 2)
    files = [png_data_path, zlib_data_path]

    ratios_jpg = []
    ratios_raw = []
    errs_jpg = []
    errs_raw = []

    for i in range(2):
        size = parse_logfile(files[i], 2)
        tmp_jpg = np.array(size) / baseline_jpg * 100
        tmp_raw = np.array(size) / baseline_raw * 100
        ratio_jpg, err_jpg = calc_ci(tmp_jpg)
        ratio_raw, err_raw = calc_ci(tmp_raw)
        ratios_jpg.append(ratio_jpg)
        ratios_raw.append(ratio_raw)
        errs_jpg.append(err_jpg)
        errs_raw.append(err_raw)
    
    fig = plt.figure()
    plt.bar(x+0.05, ratios_jpg, yerr=errs_jpg, width=0.1, align='center',
                 color='#f33c74', hatch='x')
    for a, b in zip(x, np.round(ratios_jpg, 1)):
        plt.text(a-0.01, b + 2, str(b) + ' / 98.3%', color='k')
    plt.bar(x-0.05, ratios_raw, yerr=errs_raw, width=0.1, align='center',
                 color='b', hatch='//')
    for a, b in zip(x, np.round(ratios_raw, 1)):
        plt.text(a - 0.15, b + 2, str(b) + ' / 98.3%', color='k')
    plt.legend(('JPEG Input', 'Raw Input'), loc='upper left')
    plt.ylabel('Size of compressed feature maps/Size of original feature maps(\%)')
    plt.xlabel('Compression methods')
    plt.xticks(x, x_names)
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\png_zlib.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #6
0
def plot_compressibility_approaches():
    tex.setup(width=2, l=0.1, r=0.9, t=0.9, b=0.1)
    x = np.arange(7)
    xnames = ['Baseline', 'zlib', '3 decimals', '2 decimals',
              '1 decimal', 'Normed Cut', 'Cut']
    patterns = ['/', '\\', '+']
    base = './logs_pedes/'
    files = ['log_float_decimals_10.log', 'log_float_decimals_3.log', 'log_float_decimals_2.log',
             'log_float_decimals_1.log', 'log_cut_norm.log', 'log_cut_orig.log']
    size_orig = 3115008
    ratio = [1]
    ratio_err = [0]
    for f in files:
        f_name = base + f
        data = open(f_name).readlines()[1:]
        ratios = size_orig / np.array([int(i.split()[2]) for i in data])
        mean, err = calc_ci(ratios)
        ratio.append(mean)
        ratio_err.append(err)

    ap = np.array([23.3, 23.3, 23.3, 23.3, 23.3, 23.3, 22.9]) / 23.3 * 100

    fig, ax1 = plt.subplots()
    color1 = 'darkblue'
    ax1.set_ylabel('Average Precision(\%)', color=color1)
    l1 = ax1.scatter(x - 0.2, ap,color=color1)
    for a, b in zip(x, np.round(ap, 1)):
        ax1.text(a - 0.4, b + 0.3, str(b), color=color1)
    ax1.tick_params(axis='y', labelcolor=color1)
    plt.ylim(95, 102)
    ax2 = ax1.twinx()
    ax2.set_ylabel('Compressibility(times)', color='k')
    l2 = ax2.bar(x, ratio, yerr=ratio_err, width=0.2, align='center',
                 color='lightslategrey', hatch='//')
    for a, b in zip(x, np.round(ratio, 1)):
        ax2.text(a, b + 0.4, str(b)+'x')
    ax2.tick_params(axis='y', labelcolor='k')
    plt.xticks(x, xnames)
    ax2.legend([l1, l2], ('Average Precision', 'Compression Ratio'))
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\approaches.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #7
0
def plot_accu_quality():
    tex.setup(width=1, l=0.15, r=0.9, b=0.15, t=0.9)
    x = np.arange(20, 100, 10)
    jpg_accu = np.array([13.9, 18.8, 21.0, 22.1, 22.6,
                         23.0, 23.2, 23.2]) / 23.3 * 100
    webp_accu = np.array([19.0, 21.4, 22.4, 22.8, 23.0,
                          23.0, 23.2, 23.3]) / 23.3 * 100

    fig = plt.figure()

    plt.plot(x, jpg_accu, 'g', ls='--')
    plt.scatter(x, jpg_accu, color='', marker='o', edgecolors='g')
    plt.plot(x, webp_accu, 'b')
    plt.scatter(x, webp_accu, color='', marker='o', edgecolors='b')
    plt.xlabel('Quality')
    plt.ylabel('Average Precision(\%)')
    plt.legend(('JPEG', 'WEBP'))

    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\accu_quality_comp.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #8
0
def plot_prune_ap():
    tex.setup(width=2, l=0.1, r=0.9, b=0.1, t=0.9)
    x = np.array([10, 20, 40, 60, 80, 100, 120, 140, 160, 180])
    accu = np.array([20.0, 22.8, 23.1, 23.1, 23.2, 23.2,
                     23.3, 23.3, 23.3, 23.3]) / 23.3 * 100
    base = './logs_pedes/log_prune_factor_{}.log'
    pruned = []
    errs = []
    for pf in x:
        data = parse_logfile(base.format(pf), 3, False)
        ratio = (778752 - np.array(data)) / 778752 * 100
        mean, err = calc_ci(ratio)
        pruned.append(mean)
        errs.append(err)

    color1 = 'darkblue'
    fig, ax1 = plt.subplots()
    ax1.set_xlabel('Prune Factor')
    ax1.set_ylabel('Average Precision(\%)', color=color1)
    ax1.plot(x, accu, color=color1)
    ax1.scatter(x, accu, color=color1)
    for a, b in zip(x, np.round(accu, 1)):
        ax1.text(a - 5, b+0.8, str(b), color=color1)
    ax1.tick_params(axis='y', labelcolor='k')
    plt.ylim(70, 102)

    ax2 = ax1.twinx()
    ax2.set_ylabel(
        'Params after pruning/Params before pruning(\%)', color='k')
    ax2.bar(x, pruned, width=5, yerr=errs,
            align='center', color='lightslategrey', hatch='//')
    for a, b in zip(x, np.round(pruned, 1)):
        ax2.text(a, b + 5, str(b))
    ax2.tick_params(axis='y', labelcolor='k')
    plt.xticks(x)
    plt.ylim(0, 100)
    plt.grid()
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\prune_performance.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #9
0
def plot_params_summary():
    tex.setup(width=2, l=0.1, r=0.9, b=0.3, t=0.7)
    filepath = './logs_pedes/params.txt'
    with open(filepath, 'r') as f:
        content = f.readlines()[1:]
    outputs = []
    res_d = {}
    for line in content:
        data = line.split()
        layer_num = int(data[0])
        name = data[1]+'\_'+'{}'.format(layer_num+1)
        if data[1] == 'conv':
            res_d[name] = np.prod([int(i) for i in data[5].split('x')])
        elif data[1] == 'max' or data[1]=='reorg':
            res_d[name] = np.prod([int(i) for i in data[4].split('x')])
        else:
            continue
    res_d = sorted(res_d.items(), key=lambda x: int(x[0].split('\_')[1]))
    fig= plt.figure()
    ax = plt.gca()
    ax.spines['top'].set_position(('data', 16000000))
    ax.spines['left'].set_bounds(0, 16000000)
    ax.spines['right'].set_bounds(0, 16000000)
    xnames = [i[0] for i in res_d]
    values = [i[1] for i in res_d]
    plt.axhline(y=608*608*3, color='r', linestyle='--')
    plt.text(-4, 608*608*3, 'input', color='r')
    x = np.arange(len(xnames))
    plt.bar(x, values, hatch='\\')
    for i in range(len(xnames)):
        plt.text(i, values[i]+3000000, '\%'+str(int(values[i]/(608*608*3)*100)), rotation=90)
    plt.xticks(x, xnames, rotation=90)
    plt.ticklabel_format(useOffset=False, axis='y', style='plain')
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\params_num.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #10
0
def plot_fmaps_space_analysis():
    tex.setup(width=1, l=0.25, r=0.95, b=0.1, t=0.9)
    f = open('./logs_pedes/log_space_analysis_coco.log')
    data = f.readlines()
    res = np.zeros(shape=(5000, 6))
    for ln, line in enumerate(data):
        counts = np.array([int(i) for i in line.split()])
        res[ln] = counts
    ave = np.average(res, 0)
    total = ave[0]
    r = []
    last = 0
    for i in ave[1:]:
        cur = i - last
        tmp = cur / total * 100
        last = i
        r.append(tmp)
    r.append((total - ave[-1]) / total * 100)
    x = np.arange(6)
    xnames = ['[0, R/100)', '[R/100, R/50)', '[R/50, R/20)', '[R/20, R/10)', '[R/10, R/5)', 'Others']
    fig, ax = plt.subplots()
    ax.spines['right'].set_position(('data', 51))
    ax.spines['top'].set_bounds(0, 51)
    ax.spines['bottom'].set_bounds(0, 51)
    ax.barh(x, r, color='b', align='center')
    for a, b in zip(x, r):
        ax.text(b, a, str(np.round(b, 1)))
    ax.set_yticks(x)
    ax.set_yticklabels(xnames)
    ax.invert_yaxis()  # labels read top-to-bottom
    ax.set_xlabel('Percentage of parameters')
    ax.set_xticks([], [])
    plt.grid()
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\fmaps_space_analysis.pdf',
                format='pdf', dpi=1000)
    plt.show()
Exemple #11
0
def accu_ratio(method='jpeg'):
    '''
    method = 'jpeg' or 'webp'
    '''
    tex.setup(width=2, l=0.1, r=0.9, b=0.1, t=0.9)
    x = np.arange(20, 100, 10)
    baseline_raw = 608 * 608 * 3
    baseline_jpg = parse_logfile('./logs_pedes/resized_size.log', 0)

    accu_baseline = 23.3
    jpg_accu = [13.9, 18.8, 21.0, 22.1, 22.6, 23.0, 23.2, 23.2]
    jpg_accu_delta = np.array(jpg_accu) / accu_baseline
    webp_accu = [19.0, 21.4, 22.4, 22.8, 23.0, 23.0, 23.2, 23.3]
    webp_accu_delta = np.array(webp_accu) / accu_baseline

    if method == 'jpeg':
        base = './logs_pedes/log_jpeg_q_{}.log'
        accu = jpg_accu_delta * 100
    if method == 'webp':
        base = './logs_pedes/log_webp_q_{}.log'
        accu = webp_accu_delta * 100

    qs = np.arange(20, 100, 10)
    ratios_raw = []
    ratios_jpg = []
    err_raw = []
    err_jpg = []
    for q in qs:
        data = parse_logfile(base.format(q), 2, False)
        data_raw = np.array(data) / baseline_raw * 100
        data_jpg = np.array(data) / baseline_jpg * 100
        raw_mean, raw_err = calc_ci(data_raw)
        jpg_mean, jpg_err = calc_ci(data_jpg)
        ratios_raw.append(raw_mean)
        ratios_jpg.append(jpg_mean)
        err_raw.append(raw_err)
        err_jpg.append(jpg_err)

    color1 = 'darkblue'
    fig, ax1 = plt.subplots()
    ax1.set_xlabel('Quality Factor')
    ax1.set_ylabel('Average Precision(\%)', color=color1)
    ax1.plot(x, accu, color=color1)
    ax1.scatter(x, accu, color=color1)
    for a, b in zip(x, np.round(accu, 1)):
        ax1.text(a - 3, b + 1, str(b), color=color1)
    ax1.tick_params(axis='y', labelcolor=color1)
    plt.ylim(50, 103)

    ax2 = ax1.twinx()
    ax2.set_ylabel(
        'Size of compressed image/Size of original image(\%)', color='k')
    ax2.bar(x - 0.75, ratios_jpg, width=1.5, yerr=err_jpg,
            align='center', color='#f33c74', hatch='//')
    for a, b in zip(x, np.round(ratios_jpg, 1)):
        ax2.text(a-0.5, b + 0.5, str(b))
    ax2.bar(x + 0.75, ratios_raw, width=1.5, yerr=err_raw,
            align='center', color='purple', hatch='x')
    for a, b in zip(x, np.round(ratios_raw, 1)):
        ax2.text(a + 1, b + 1, str(b))
    ax2.tick_params(axis='y', labelcolor='k')
    ax2.legend(('JPEG Input', 'Raw Input'), loc=2)
    # plt.ylim(0, 130)
    plt.xticks(x)
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\ratio_ap_quality_{}.pdf'.format(method), format='pdf', dpi=1000)
    plt.show()
Exemple #12
0
def plot_image_based_all(base='jpg'):
    """
    base: 'jpg' for jpeg input
          'raw' for raw input
    """
    tex.setup(width=2, l=0.1, r=0.9, b=0.1, t=0.9)
    baseline_raw = 608 * 608 * 3
    baseline_jpg = parse_logfile('./logs_pedes/resized_size.log', 0)

    jpg_accu = np.array([13.9, 18.8, 21.0, 22.1, 22.6,
                         23.0, 23.2, 23.2]) / 23.3 * 100
    webp_accu = np.array([19.0, 21.4, 22.4, 22.8, 23.0,
                          23.0, 23.2, 23.3]) / 23.3 * 100
    h264_slower_accu = np.array(
        [2.1, 8.9, 16.3, 19.9, 21.1, 21.5]) / 23.3 * 100
    h264_medium_accu = np.array(
        [1.4, 7.0, 14.5, 19.1, 20.8, 21.4]) / 23.3 * 100
    h264_faster_accu = np.array(
        [0.9, 4.8, 12.8, 18.1, 20.3, 21.4]) / 23.3 * 100
    h264_ultrafast_accu = np.array(
        [15, 18.7, 20.2, 20.9, 21.3, 21.4]) / 23.3 * 100

    def get_plot_data(method):
        if method == 'jpeg':
            base = './logs_pedes/log_jpeg_q_{}.log'
        if method == 'webp':
            base = './logs_pedes/log_webp_q_{}.log'
        if method == 'h264_slower':
            base = './logs_pedes/log_h264_preset_slower_crf_{}.log'
        if method == 'h264_medium':
            base = './logs_pedes/log_h264_preset_medium_crf_{}.log'
        if method == 'h264_faster':
            base = './logs_pedes/log_h264_preset_faster_crf_{}.log'
        if method == 'h264_ultrafast':
            base = './logs_pedes/log_h264_preset_ultrafast_crf_{}.log'

        qs = np.arange(20, 100, 10) # 20, 30, 40, ..., 90
        crfs = np.arange(30, 18, -2) # 30 28, 26, 24, 22, 20
        params = [qs, crfs]
        flag = 1
        if 'jpeg' in method or 'webp' in method:
            flag = 0
        ratios_raw = []
        ratios_jpg = []
        err_raw = []
        err_jpg = []
        for param in params[flag]:
            data = parse_logfile(base.format(param), 2, False)
            data_raw = np.array(data) / baseline_raw * 100
            data_jpg = np.array(data) / baseline_jpg * 100
            raw_mean, raw_err = calc_ci(data_raw)
            jpg_mean, jpg_err = calc_ci(data_jpg)
            ratios_raw.append(raw_mean)
            ratios_jpg.append(jpg_mean)
            err_raw.append(raw_err)
            err_jpg.append(jpg_err)
        return ratios_raw, ratios_jpg, err_raw, err_jpg

    ratios_raw_jpeg, ratios_jpg_jpeg, err_raw_jpeg, err_jpg_jpeg = get_plot_data(
        'jpeg')
    ratios_raw_webp, ratios_jpg_webp, err_raw_webp, err_jpg_webp = get_plot_data(
        'webp')
    ratios_raw_h264_slower, ratios_jpg_h264_slower, err_raw_h264_slower, err_jpg_h264_slower = get_plot_data(
        'h264_slower')
    ratios_raw_h264_medium, ratios_jpg_h264_medium, err_raw_h264_medium, err_jpg_h264_medium = get_plot_data(
        'h264_medium')
    ratios_raw_h264_faster, ratios_jpg_h264_faster, err_raw_h264_faster, err_jpg_h264_faster = get_plot_data(
        'h264_faster')
    ratios_raw_h264_ultrafast, ratios_jpg_h264_ultrafast, err_raw_h264_ultrafast, err_jpg_h264_ultrafast = get_plot_data(
        'h264_ultrafast')

    fig = plt.figure()
    ratios = {'jpg': [ratios_jpg_jpeg, ratios_jpg_webp, ratios_jpg_h264_slower, 
                    ratios_jpg_h264_medium, ratios_jpg_h264_faster, ratios_jpg_h264_ultrafast],
              'raw': [ratios_raw_jpeg, ratios_raw_webp, ratios_raw_h264_slower, 
                    ratios_raw_h264_medium, ratios_raw_h264_faster, ratios_raw_h264_ultrafast]}

    errs = {'jpg': [err_jpg_jpeg, err_jpg_webp, err_jpg_h264_slower, 
                err_jpg_h264_medium, err_jpg_h264_faster, err_jpg_h264_ultrafast], 
            'raw': [err_raw_jpeg, err_raw_webp, err_raw_h264_slower,
                err_raw_h264_medium, err_raw_h264_faster, err_raw_h264_ultrafast]}

    plt.errorbar(jpg_accu, ratios[base][0], yerr=errs[base][0], 
                 color='g', capsize=2)
    plt.errorbar(webp_accu, ratios[base][1], yerr=errs[base][1],
                 color='m', capsize=2)
    plt.errorbar(h264_slower_accu, ratios[base][2], yerr=errs[base][2],
                 color='b', capsize=2)
    plt.errorbar(h264_medium_accu, ratios[base][3], yerr=errs[base][3],
                 color='r', capsize=2)
    plt.errorbar(h264_faster_accu, ratios[base][4], yerr=errs[base][4],
                 color='k', capsize=2)
    plt.errorbar(h264_ultrafast_accu, ratios[base][5], yerr=errs[base][5],
                 color='y', capsize=2)
    plt.xlabel('Average Precision(\%)')
    plt.ylabel('Size of compressed image/Size of original image(\%)')
    # plt.legend(('H264 slower', 'H264 medium', 'H264 faster', 'H264 ultrafast'))
    plt.legend(('JPEG', 'WEBP', 'H264 slower', 'H264 medium', 'H264 faster', 'H264 ultrafast'))
    plt.xlim(80, 102)
    plt.xticks(np.arange(80, 102, step=1))
    if base == 'jpg':
        ax1 = plt.gca()
        print(ax1.get_xlim())
        plt.axvline(98.7, 0, 50 / ax1.get_ylim()[1], linestyle='--')
        plt.axhline(50, 0, (98.7 - 80) / (ax1.get_xlim()[1] - 80), linestyle='--')

    left, bottom, width, height = 0.3, 0.5, 0.2, 0.3
    ax2 = fig.add_axes([left, bottom, width, height])
    ax2.errorbar(jpg_accu, ratios[base][0], yerr=errs[base][0], 
                 color='g', capsize=2)
    ax2.errorbar(webp_accu, ratios[base][1], yerr=errs[base][1],
                 color='m', capsize=2)
    ax2.errorbar(h264_slower_accu, ratios[base][2], yerr=errs[base][2],
                 color='b', capsize=2)
    ax2.errorbar(h264_medium_accu, ratios[base][3], yerr=errs[base][3],
                 color='r', capsize=2)
    ax2.errorbar(h264_faster_accu, ratios[base][4], yerr=errs[base][4],
                 color='k', capsize=2)
    ax2.errorbar(h264_ultrafast_accu, ratios[base][5], yerr=errs[base][5],
                 color='y', capsize=2)
    ax2.set_xlim(80, 90)
    if base == 'jpg':
        ax2.set_ylim(15, 50)
    else:
        ax2.set_ylim(2.5, 12.5)

    # left, bottom, width, height = 0.5, 0.4, 0.2, 0.3
    # ax3 = fig.add_axes([left, bottom, width, height])
    # ax3.errorbar(jpg_accu, ratios[base][0], yerr=errs[base][0], 
    #              color='g', capsize=2)
    # ax3.errorbar(webp_accu, ratios[base][1], yerr=errs[base][1],
    #              color='m', capsize=2)
    # ax3.errorbar(h264_slower_accu, ratios[base][2], yerr=errs[base][2],
    #              color='b', capsize=2)
    # ax3.errorbar(h264_medium_accu, ratios[base][3], yerr=errs[base][3],
    #              color='r', capsize=2)
    # ax3.errorbar(h264_faster_accu, ratios[base][4], yerr=errs[base][4],
    #              color='k', capsize=2)
    # ax3.errorbar(h264_ultrafast_accu, ratios[base][5], yerr=errs[base][5],
    #              color='y', capsize=2)
    # ax3.set_xlim(90, 101)

    # plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\h264_comp_jpg.pdf'.format(base),
    #             format='pdf', dpi=1000)
    plt.savefig('C:\\d\\diplomarbeit\\DA\\Figures\\image_based_approached_{}.pdf'.format(base),
                format='pdf', dpi=1000)
    plt.show()