def main(dataset='measurements.npy'):
    data = np.load(dataset, mmap_mode='r')
    print 'loaded', dataset, data.shape

    fig = plt.figure()
    ax = util.axes(fig, 111)

    trial = data[15, 1, 5]
    for f in range(0, len(trial), 300):
        util.plot_skeleton(ax, trial[f], alpha=1)
    x, y, z = trial[:, TARGET].T
    ax.plot(x, z, y, 'o-', color='#111111', alpha=0.5)

    util.set_limits(ax, center=(0, 0, 1), span=1)

    ax.w_xaxis.set_pane_color((1, 1, 1, 1))
    ax.w_yaxis.set_pane_color((1, 1, 1, 1))
    ax.w_zaxis.set_pane_color((1, 1, 1, 1))

    #plt.gcf().set_size_inches(12, 10)
    #plt.savefig('single-trial.pdf', dpi=600)
    plt.show()
Exemple #2
0
        return transformed_frames[:, :, :2]

    # apply T
    transformed_sequences = np.asarray(
        [_transform_sequence(seq) for seq in sequences])

    return transformed_sequences


if __name__ == '__main__':
    # read in sequence
    dataset_dir = Path(__file__).parent / '../../datasets/KTH_Action_Dataset/'
    metadata_file = dataset_dir / 'metadata.csv'
    from datasets import KTHDataset
    dataset = KTHDataset(metadata_file,
                         dataset_dir,
                         use_confidence_scores=False)
    seqs, actions = dataset[:4]
    original_seq = np.copy(seqs[0])

    augmented_sequences = augment_data(seqs[:4])

    assert np.array_equal(seqs[0],
                          original_seq)  # check original sequence still intact

    from util import plot_skeleton
    print('Saving plot of skeleton')
    plot_skeleton(augmented_sequences[0],
                  '../../datasets/example_augmented_plot.mp4')
def main(dataset='measurements.npy'):
    data = np.load(dataset, mmap_mode='r')
    print 'loaded', dataset, data.shape

    plots = list(range(N * N))
    frames = [[] for _ in plots]
    for subj in data:
        for block in subj[1:]:
            for trial in block:
                if trial[0, C.col('trial-hand')] == C.right:
                    for frame in trial:
                        for i in plots:
                            if within_region(frame, i):
                                frames[i].append(frame)
                                break

    u, v = np.mgrid[0:2 * np.pi:11j, 0:np.pi:7j]
    sphx = np.cos(u) * np.sin(v)
    sphy = np.sin(u) * np.sin(v)
    sphz = np.cos(v)

    fig = plt.figure()
    for i, postures in enumerate(frames):
        if not postures:
            continue
        if i != 2:
            continue

        postures = np.array(postures)
        for m in range(50):
            marker = postures[:, 17+m*4:17+(m+1)*4]
            drops = marker[:, 3] < 0
            marker[drops, :3] = marker[~drops, :3].mean(axis=0)
        means = postures.mean(axis=0)
        stds = postures.std(axis=0)

        #ax = util.axes(fig, 111)
        #for frame in postures[::5]:
        #    util.plot_skeleton(ax, frame, alpha=0.1)
        ax = util.axes(fig, 110 * N + i + 1)
        util.plot_skeleton(ax, means, alpha=1.0)
        for m in range(50):
            mx, my, mz = means[17+m*4:20+m*4]
            sx, sy, sz = stds[17+m*4:20+m*4] / 2
            ax.plot_wireframe(sphx * sx + mx, sphz * sz + mz, sphy * sy + my,
                              color=C.MARKER_COLORS[m], alpha=0.3)

        #tgtx, tgty, tgtz = postures.mean(axis=0)[
        #    C.cols('target-x', 'target-y', 'target-z')]
        #ax.plot([tgtx], [tgtz], [tgty], 'o', color='#111111')

        #for m in range(50):
        #    marker = postures[:, 17 + 4 * m:17 + 4 * (m+1)]
        #    position = marker.mean(axis=0)
        #    size = marker.std(axis=0)
        #    ax.plot_surface()

        util.set_limits(ax, center=(0, -0.5, 1), span=1)
        ax.w_xaxis.set_pane_color((1, 1, 1, 1))
        ax.w_yaxis.set_pane_color((1, 1, 1, 1))
        ax.w_zaxis.set_pane_color((1, 1, 1, 1))
        ax.set_title(['Top Right', 'Top Left', 'Bottom Right', 'Bottom Left'][i])

    #for m in range(50):
    #    x, z, y = frame[m*4:m*4+3]
    #    ax.text(x, y, z, str(m))

    plt.gcf().set_size_inches(12, 10)
    #plt.savefig('reach-targets-with-variance.pdf', dpi=600)
    plt.show()