def make_fine(idrive, filename=None): if filename is None: filename = "drive%02d_fine.npy" % idrive video = load_stereo_video(idrive) # video = video[:3] n_disp = 128 fine_params = { 'data_weight': 0.01289, 'disc_max': 411.9, 'data_max': 2382540., 'ksize': 15, 'iters': 10 } # 2.023 # disps = [] disps = np.zeros((len(video), ) + video[0][0].shape, dtype='uint8') for i, frame in enumerate(video): tic('BP frame %d' % i) disp = fine_bp(frame, values=n_disp, **fine_params) toc() # print disp.dtype # disps.append(disp) disps[i] = disp # disps = np.array(disps) np.save(filename, disps)
def estimate_coarse_error(down_factor, iters, video, n_disp, drive, n_frames=20, **params): # TODO: use fine BP as ground truth? coarse_error = [] for i in range(n_frames): print(i) frame = video[i] tic('coarse') coarse_disp = coarse_bp(frame, down_factor=down_factor, iters=iters, **params) toc() xyd = load_disparity_points(drive, i) coarse_error.append(error_on_points(xyd, coarse_disp, n_disp, kind='close')) return np.mean(coarse_error)
def test_tic_toc(): rng = np.random.RandomState(0) n = int(1e6) tic() rng.normal(size=n) t0 = toc() tic() rng.normal(size=5 * n) t1 = toc() assert 0.001 <= t0 <= 10 assert 3 * t0 <= t1 <= 30
def test_shift_images(): # n = 5 # images = np.zeros((n, 9)) # shape = (3, 3) # images[np.arange(n), 4] = 1 # images2 = shift_images(images, shape) # for image in images2: # print image.reshape(shape) # --- timing test from hunse_tools.timing import tic, toc [train_images, _], _, _ = mnist() tic() images2 = shift_images(train_images, (28, 28)) toc()
n_vis, eval_points=images, encoders=encoders, intercepts=[-0.5] * n_hid, max_rates=[200] * n_hid) o = nengo.Node(size_in=n_vis) op = nengo.Probe(o, synapse=0.03) ca = nengo.Connection(u, a) co = nengo.Connection(a, o) from hunse_tools.timing import tic, toc tic() sim = nengo.Simulator(model) toc() tic() sim.run(1.0) toc() x = sim.data[up].reshape(-1, 28, 28) y = sim.data[op].reshape(-1, 28, 28) plt.figure(1) plt.clf() plt.subplot(121) plt.imshow(x.mean(0), cmap='gray') plt.subplot(122) plt.imshow(y.mean(0), cmap='gray') # --- check RMSEs over a number of builds
full_values = 128 frame_down_factor = 1 values = full_values / 2**frame_down_factor iters = 3 params = { 'data_weight': 0.16145115747533928, 'disc_max': 294.1504935618425, 'data_max': 32.024780646200725, 'ksize': 3} frame = (downsample(frame[0], frame_down_factor), downsample(frame[1], frame_down_factor)) tic() coarse_disp = coarse_bp(frame, values=values, down_factor=1, iters=iters, **params) coarse_disp *= 2**frame_down_factor toc() tic() fine_disp = coarse_bp(frame, values=values, down_factor=0, iters=iters, **params) fine_disp *= 2**frame_down_factor toc() # fovea_corners = (60, 360) # fovea_shapes = (80, 80) fovea_corners = [(60, 160), (60, 360)] fovea_shapes = [(80, 80), (80, 80)] fovea_corners = np.array(fovea_corners, ndmin=2) fovea_shapes = np.array(fovea_shapes, ndmin=2) tic()