nnet_params_filename, input_filename, output_filename = sys.argv[1:4]
    moviedir = sys.argv[4] if len(sys.argv) == 5 else None
    sigmasq_states = 0.1**2

    with open(nnet_params_filename, 'r') as infile:
        nnet_params = pickle.load(infile)

    print 'loading from {}...'.format(input_filename)
    with open_pkl_or_pklgz(input_filename, 'r') as infile:
        datadict = pickle.load(infile)
    print '...done!'

    # reorient each video
    print 're-orienting video sequences...'
    reoriented_datadict = \
        {name: reorient_video(nnet_params, frames, sigmasq_states, inflate_vars=1.)
         for name, frames in iteritems(datadict)}
    print '...done!'

    # save the result
    print 'saving to {}...'.format(output_filename)
    with open(output_filename, 'w') as outfile:
        pickle.dump(reoriented_datadict, outfile, protocol=-1)
    print '...done!'

    # make some movies
    if moviedir:
        print 'making movies...'
        for name, frames in reoriented_datadict.iteritems():
            name = os.path.split(name)[-1] + '.mp4'
            make_movie(frames, os.path.join(moviedir, name))
예제 #2
0
from mouse_orientation.canonicalize import infer_angles, reorient_video
from mouse_orientation.regression import predict
from mouse_orientation.kalman import kalman_smoother


if __name__ == "__main__":
    sigmasq_states = 0.1**2

    with open('data/nnet_params.pkl', 'r') as infile:
        nnet_params = pickle.load(infile)

    with open('data/test_frames_dict.pkl', 'r') as infile:
        datadict = pickle.load(infile)

    ### manual viz
    frames = clean_frames(datadict['test'])
    mus, log_sigmasqs = predict(frames.reshape(frames.shape[0], -1), nnet_params)
    plt.errorbar(np.arange(len(frames)), mus, np.exp(log_sigmasqs / 2.))
    plt.plot(kalman_smoother(
        0., 100., 1., sigmasq_states, mus, np.exp(log_sigmasqs))[0], 'g-')

    ### a look at results
    sl = slice(270, 290)
    # sl = slice(None)
    rotated_frames = reorient_video(nnet_params, frames, sigmasq_states)
    plt.matshow(np.vstack((np.hstack(frames), np.hstack(rotated_frames))), cmap='plasma')
    plt.xlim(sl.start*30, sl.stop*30)

    plt.show()
    plt.show()
예제 #3
0
    nnet_params_filename, input_filename, output_filename = sys.argv[1:4]
    moviedir = sys.argv[4] if len(sys.argv) == 5 else None
    sigmasq_states = 0.1**2

    with open(nnet_params_filename, 'r') as infile:
        nnet_params = pickle.load(infile)

    print 'loading from {}...'.format(input_filename)
    with open_pkl_or_pklgz(input_filename, 'r') as infile:
        datadict = pickle.load(infile)
    print '...done!'

    # reorient each video
    print 're-orienting video sequences...'
    reoriented_datadict = \
        {name: reorient_video(nnet_params, frames, sigmasq_states, inflate_vars=1.)
         for name, frames in iteritems(datadict)}
    print '...done!'

    # save the result
    print 'saving to {}...'.format(output_filename)
    with open(output_filename, 'w') as outfile:
        pickle.dump(reoriented_datadict, outfile, protocol=-1)
    print '...done!'

    # make some movies
    if moviedir:
        print 'making movies...'
        for name, frames in reoriented_datadict.iteritems():
            name = os.path.split(name)[-1] + '.mp4'
            make_movie(frames, os.path.join(moviedir, name))