예제 #1
0
파일: report.py 프로젝트: BoAdBo/AlphaPose
def trainingoverview(dataset, dists, filts, filtnames, pdf=None,
                     other_dists=None, parts_to_show=None, exp_id='default'):
    # Initialize blank page
    fig = plt.figure(figsize=(8.5,11), dpi=100, facecolor='w')

    # Default parts to show performance results
    if parts_to_show is None:
        parts_to_show = []
        if dataset == 'flic': parts_to_show += [('Face',['leye','reye','nose'])]
        else: parts_to_show += [('Head',['head','neck']),
                                ('Ank',['lank','rank']),
                                ('Knee',['lkne','rkne'])]
        parts_to_show += [('Sho',['lsho','rsho']),
                          ('Elb',['lelb','relb']),
                          ('Wri',['lwri','rwri']),
                          ('Hip',['lhip','rhip'])]
    part_labels = [parts_to_show[i][0] for i in xrange(len(parts_to_show))]

    # Load training logs
    log_dir = ref.posedir + '/exp/' + dataset + '/' + exp_id
    train_log = np.loadtxt(log_dir + '/train.log', skiprows=1)
    test_log = np.loadtxt(log_dir + '/test.log', skiprows=1)
    # Plot loss
    ax = fig.add_subplot(4,1,2)
    plottraintest(ax, train_log, test_log)

    # Setup table to hold performance numbers
    ax_table = fig.add_subplot(4,1,1)
    cols = ['Label'] + part_labels
    rows = filtnames
    if other_dists is not None:
        rows += other_dists.keys()
    setuptable(ax_table, len(rows)+1, len(cols), row_labels=rows, col_labels=cols)
    ax_table.set_title('%s - Experiment: %s' % (dataset.upper(), exp_id), y=1.05)

    # Generate PDJ charts for each part
    num_cols = 4
    for i,pts in enumerate(parts_to_show):
        ax = fig.add_subplot(4,num_cols,i+2*num_cols+1)
        setuppdjplot(ax, i, len(parts_to_show), num_cols)

        for j,filt in enumerate(filts):
            d, t = eval.pdjdata(dataset, dists, filt=filt, partnames=pts[1])
            # Plot PDJ curve
            ax.plot(t,d,label=filtnames[j])
            # Display performance number in table
            tabletext(ax_table, '%04.1f'%(d[-1]*100), j+1, i+1)
        if other_dists is not None:
            for j,k in enumerate(other_dists):
                d, t = eval.pdjdata(dataset, other_dists[k][0], filt=other_dists[k][1], partnames=pts[1])
                # Plot PDJ curve
                ax.plot(t,d,label=k)
                # Display performance number in table
                tabletext(ax_table, '%04.1f'%(d[-1]*100), j+1+len(filts), i+1)

        ax.set_title(pts[0], fontsize=10)
        ax.set_ylim([0,1])

        if i == len(parts_to_show) - 1:
            ax_labels = filtnames
            if other_dists is not None:
                ax_labels += other_dists.keys()
            ax.legend(loc='upper left', bbox_to_anchor=(1.1, 1), fontsize=11)

    if pdf: pdf.savefig()
    else: plt.show()
예제 #2
0
def trainingoverview(dataset, dists, filts, filtnames, pdf=None,
                     other_dists=None, parts_to_show=None, exp_id='default'):
    # Initialize blank page
    fig = plt.figure(figsize=(8.5,11), dpi=100, facecolor='w')

    # Default parts to show performance results
    if parts_to_show is None:
        parts_to_show = []
        if dataset == 'flic': parts_to_show += [('Face',['leye','reye','nose'])]
        else: parts_to_show += [('Head',['head','neck']),
                                ('Ank',['lank','rank']),
                                ('Knee',['lkne','rkne'])]
        parts_to_show += [('Sho',['lsho','rsho']),
                          ('Elb',['lelb','relb']),
                          ('Wri',['lwri','rwri']),
                          ('Hip',['lhip','rhip'])]
    part_labels = [parts_to_show[i][0] for i in xrange(len(parts_to_show))]

    # Load training logs
    log_dir = ref.posedir + '/exp/' + dataset + '/' + exp_id
    train_log = np.loadtxt(log_dir + '/train.log', skiprows=1)
    test_log = np.loadtxt(log_dir + '/test.log', skiprows=1)
    # Plot loss
    ax = fig.add_subplot(4,1,2)
    plottraintest(ax, train_log, test_log)

    # Setup table to hold performance numbers
    ax_table = fig.add_subplot(4,1,1)
    cols = ['Label'] + part_labels
    rows = filtnames
    if other_dists is not None:
        rows += other_dists.keys()
    setuptable(ax_table, len(rows)+1, len(cols), row_labels=rows, col_labels=cols)
    ax_table.set_title('%s - Experiment: %s' % (dataset.upper(), exp_id), y=1.05)

    # Generate PDJ charts for each part
    num_cols = 4
    for i,pts in enumerate(parts_to_show):
        ax = fig.add_subplot(4,num_cols,i+2*num_cols+1)
        setuppdjplot(ax, i, len(parts_to_show), num_cols)

        for j,filt in enumerate(filts):
            d, t = eval.pdjdata(dataset, dists, filt=filt, partnames=pts[1])
            # Plot PDJ curve
            ax.plot(t,d,label=filtnames[j])
            # Display performance number in table
            tabletext(ax_table, '%04.1f'%(d[-1]*100), j+1, i+1)
        if other_dists is not None:
            for j,k in enumerate(other_dists):
                d, t = eval.pdjdata(dataset, other_dists[k][0], filt=other_dists[k][1], partnames=pts[1])
                # Plot PDJ curve
                ax.plot(t,d,label=k)
                # Display performance number in table
                tabletext(ax_table, '%04.1f'%(d[-1]*100), j+1+len(filts), i+1)

        ax.set_title(pts[0], fontsize=10)
        ax.set_ylim([0,1])

        if i == len(parts_to_show) - 1:
            ax_labels = filtnames
            if other_dists is not None:
                ax_labels += other_dists.keys()
            ax.legend(loc='upper left', bbox_to_anchor=(1.1, 1), fontsize=11)

    if pdf: pdf.savefig()
    else: plt.show()
예제 #3
0
파일: report.py 프로젝트: BoAdBo/AlphaPose
def filtercomparison(dataset, dists, filts, filtnames, pdf=None, title='Performance comparison', other_dists=None, parts_to_show=None):
    # Initialize blank page
    # plt.clf()
    fig = plt.figure(figsize=(8.5,11), dpi=100, facecolor='w')

    if parts_to_show is None:
        part_labels = ref.pair_names[dataset]
        parts_to_show = ref.part_pairs[dataset]
    else:
        part_labels = [parts_to_show[i][0] for i in xrange(len(parts_to_show))]

    # Configuration of ticks in plots
    major_ticks_y = np.arange(0,1.01,.2)
    minor_ticks_y = np.arange(0,1.01,.1)

    #-------------------------------------------------------------------
    # Table with performance numbers
    #-------------------------------------------------------------------

    ax_table = fig.add_subplot(5,1,1)

    cols = ['', '#', 'Full'] + part_labels
    rows = ['Label'] + filtnames
    num_samples = [len(dists) if filt is None else filt.sum() for filt in filts]
    num_samples = [''] + num_samples
    if other_dists is not None:
        rows += other_dists.keys()
        num_samples += [len(dists) if other_dists[k][1] is None else other_dists[k][1].sum()
                        for k in other_dists.keys()]

    # Initial table set up
    for r in xrange(len(rows)):
        # Filter labels
        ax_table.text(.1,len(rows)-.75-r,rows[r],fontsize=10,horizontalalignment='left')
        # Number of samples available from each filter
        ax_table.text(2.5,len(rows)-.75-r,num_samples[r],fontsize=10,horizontalalignment='center')
        if r < len(rows) - 1:
            thk = 1
        else:
            thk = 2
        plt.plot([0,len(cols)+1],[r,r],color='k',linewidth=thk)

    for c in xrange(1, len(cols) + 1):
        ax_table.text(c+.5,len(rows)-.75,cols[c-1],fontsize=10,horizontalalignment='center')
        if c > 2:
            thk = 1
        else:
            thk = 2
        if c < len(cols):
            plt.plot([c+1, c+1],[0,len(rows)],color='k',linewidth=thk)

    # Performance numbers get filled in as we create the PDJ charts

    ax_table.set_xlim(0,len(cols)+1)
    ax_table.get_xaxis().set_visible(False)
    ax_table.get_yaxis().set_visible(False)

    ax_table.set_title(title, y=1.05)

    #-------------------------------------------------------------------
    # Overall performance chart
    #-------------------------------------------------------------------
    ax = fig.add_subplot(5,3,4)

    ax.set_yticks(major_ticks_y)
    ax.set_yticks(minor_ticks_y, minor=True)
    for tick in ax.xaxis.get_major_ticks():
        tick.label.set_fontsize(8)
        tick.label.set_visible(False)
    for tick in ax.yaxis.get_major_ticks():
        tick.label.set_fontsize(8)

    ax.grid()
    ax.grid(which='minor', alpha=0.5)

    for i,filt in enumerate(filts):
        d, t = eval.pdjdata(dataset, dists, filt=filt)
        # Plot PDJ curve
        ax.plot(t,d)
        # Display performance number in table
        ax_table.text(3.5, len(rows)-i-1.75, '%04.1f' % (d[-1]*100),
                      fontsize=10, horizontalalignment='center')
    if other_dists is not None:
        for i,k in enumerate(other_dists):
            d, t = eval.pdjdata(dataset, other_dists[k][0], filt=other_dists[k][1])
            # Plot PDJ curve
            ax.plot(t,d)
            # Display performance number in table
            ax_table.text(3.5, len(rows)-i-len(filts)-1.75, '%04.1f' % (d[-1]*100),
                          fontsize=10, horizontalalignment='center')

    ax.set_ylim([0,1])

    #    box = ax.get_position()
    #    ax.set_position([box.x0, box.y0, box.width * 0.9, box.height])
    ax_labels = filtnames
    if other_dists is not None:
        ax_labels += other_dists.keys()
    ax.legend(loc='center left', bbox_to_anchor=(1.1, 0.5), labels=ax_labels, fontsize=11)
    ax.set_title('Overall', fontsize=10)

    #-------------------------------------------------------------------
    # Separate charts for each part
    #-------------------------------------------------------------------
    num_cols = 3
    for i,pts in enumerate(parts_to_show):
        ax = fig.add_subplot(5,num_cols,i+7)
        setuppdjplot(ax, i, len(parts_to_show), num_cols)

        for j,filt in enumerate(filts):
            d, t = eval.pdjdata(dataset, dists, filt=filt, partnames=pts)
            # Plot PDJ curve
            ax.plot(t,d)
            # Display performance number in table
            ax_table.text(i+4.5, len(rows)-j-1.75, '%04.1f' % (d[-1]*100), fontsize=10, horizontalalignment='center')
        if other_dists is not None:
            for j,k in enumerate(other_dists):
                d, t = eval.pdjdata(dataset, other_dists[k][0], filt=other_dists[k][1], partnames=pts)
                # Plot PDJ curve
                ax.plot(t,d)
                # Display performance number in table
                ax_table.text(i+4.5, len(rows)-j-1.75-len(filts), '%04.1f' % (d[-1]*100),
                              fontsize=10, horizontalalignment='center')

        ax.set_title(part_labels[i], fontsize=10)
        ax.set_ylim([0,1])

    if pdf:
        pdf.savefig()
    else:
        plt.show()
예제 #4
0
def filtercomparison(dataset, dists, filts, filtnames, pdf=None, title='Performance comparison', other_dists=None, parts_to_show=None):
    # Initialize blank page
    # plt.clf()
    fig = plt.figure(figsize=(8.5,11), dpi=100, facecolor='w')

    if parts_to_show is None:
        part_labels = ref.pair_names[dataset]
        parts_to_show = ref.part_pairs[dataset]
    else:
        part_labels = [parts_to_show[i][0] for i in xrange(len(parts_to_show))]

    # Configuration of ticks in plots
    major_ticks_y = np.arange(0,1.01,.2)
    minor_ticks_y = np.arange(0,1.01,.1)

    #-------------------------------------------------------------------
    # Table with performance numbers
    #-------------------------------------------------------------------

    ax_table = fig.add_subplot(5,1,1)

    cols = ['', '#', 'Full'] + part_labels
    rows = ['Label'] + filtnames
    num_samples = [len(dists) if filt is None else filt.sum() for filt in filts]
    num_samples = [''] + num_samples
    if other_dists is not None:
        rows += other_dists.keys()
        num_samples += [len(dists) if other_dists[k][1] is None else other_dists[k][1].sum()
                        for k in other_dists.keys()]

    # Initial table set up
    for r in xrange(len(rows)):
        # Filter labels
        ax_table.text(.1,len(rows)-.75-r,rows[r],fontsize=10,horizontalalignment='left')
        # Number of samples available from each filter
        ax_table.text(2.5,len(rows)-.75-r,num_samples[r],fontsize=10,horizontalalignment='center')
        if r < len(rows) - 1:
            thk = 1
        else:
            thk = 2
        plt.plot([0,len(cols)+1],[r,r],color='k',linewidth=thk)

    for c in xrange(1, len(cols) + 1):
        ax_table.text(c+.5,len(rows)-.75,cols[c-1],fontsize=10,horizontalalignment='center')
        if c > 2:
            thk = 1
        else:
            thk = 2
        if c < len(cols):
            plt.plot([c+1, c+1],[0,len(rows)],color='k',linewidth=thk)

    # Performance numbers get filled in as we create the PDJ charts

    ax_table.set_xlim(0,len(cols)+1)
    ax_table.get_xaxis().set_visible(False)
    ax_table.get_yaxis().set_visible(False)

    ax_table.set_title(title, y=1.05)

    #-------------------------------------------------------------------
    # Overall performance chart
    #-------------------------------------------------------------------
    ax = fig.add_subplot(5,3,4)

    ax.set_yticks(major_ticks_y)
    ax.set_yticks(minor_ticks_y, minor=True)
    for tick in ax.xaxis.get_major_ticks():
        tick.label.set_fontsize(8)
        tick.label.set_visible(False)
    for tick in ax.yaxis.get_major_ticks():
        tick.label.set_fontsize(8)

    ax.grid()
    ax.grid(which='minor', alpha=0.5)

    for i,filt in enumerate(filts):
        d, t = eval.pdjdata(dataset, dists, filt=filt)
        # Plot PDJ curve
        ax.plot(t,d)
        # Display performance number in table
        ax_table.text(3.5, len(rows)-i-1.75, '%04.1f' % (d[-1]*100),
                      fontsize=10, horizontalalignment='center')
    if other_dists is not None:
        for i,k in enumerate(other_dists):
            d, t = eval.pdjdata(dataset, other_dists[k][0], filt=other_dists[k][1])
            # Plot PDJ curve
            ax.plot(t,d)
            # Display performance number in table
            ax_table.text(3.5, len(rows)-i-len(filts)-1.75, '%04.1f' % (d[-1]*100),
                          fontsize=10, horizontalalignment='center')

    ax.set_ylim([0,1])

    #    box = ax.get_position()
    #    ax.set_position([box.x0, box.y0, box.width * 0.9, box.height])
    ax_labels = filtnames
    if other_dists is not None:
        ax_labels += other_dists.keys()
    ax.legend(loc='center left', bbox_to_anchor=(1.1, 0.5), labels=ax_labels, fontsize=11)
    ax.set_title('Overall', fontsize=10)

    #-------------------------------------------------------------------
    # Separate charts for each part
    #-------------------------------------------------------------------
    num_cols = 3
    for i,pts in enumerate(parts_to_show):
        ax = fig.add_subplot(5,num_cols,i+7)
        setuppdjplot(ax, i, len(parts_to_show), num_cols)

        for j,filt in enumerate(filts):
            d, t = eval.pdjdata(dataset, dists, filt=filt, partnames=pts)
            # Plot PDJ curve
            ax.plot(t,d)
            # Display performance number in table
            ax_table.text(i+4.5, len(rows)-j-1.75, '%04.1f' % (d[-1]*100), fontsize=10, horizontalalignment='center')
        if other_dists is not None:
            for j,k in enumerate(other_dists):
                d, t = eval.pdjdata(dataset, other_dists[k][0], filt=other_dists[k][1], partnames=pts)
                # Plot PDJ curve
                ax.plot(t,d)
                # Display performance number in table
                ax_table.text(i+4.5, len(rows)-j-1.75-len(filts), '%04.1f' % (d[-1]*100),
                              fontsize=10, horizontalalignment='center')

        ax.set_title(part_labels[i], fontsize=10)
        ax.set_ylim([0,1])

    if pdf:
        pdf.savefig()
    else:
        plt.show()