示例#1
0
def objective(args):
    # args['ksize'] = int(args['ksize'])

    costs = []
    # for index in range(3):
    # for index in range(10):
    for index in range(194):

        if index in [31, 82, 114]:  # missing frames
            continue

        source = KittiMultiViewSource(index, test=False, n_frames=0)
        full_shape = source.frame_ten[0].shape
        frame_ten = [downsample(source.frame_ten[0], frame_down_factor),
                     downsample(source.frame_ten[1], frame_down_factor)]
        frame_shape = frame_ten[0].shape

        true_points = source.get_ground_truth_points(occluded=False)

        # determine fovea shape
        fovea_pixels = np.ceil(fovea_fraction * frame_shape[0] * (frame_shape[1] - values))
        if fovea_pixels > 0:
            fovea_height = np.minimum(frame_shape[0], np.ceil(fovea_pixels ** .5))
            fovea_width = np.minimum(frame_shape[1], np.ceil(fovea_pixels / fovea_height))
            fovea_shape = fovea_height, fovea_width
        else:
            fovea_shape = (0, 0)

        # average disparity
        try:
            average_disp = source.get_average_disparity()
        except IOError:  # likely does not have a full 20 frames
            print("Skipping index %d (lacks frames)" % index)
            continue

        average_disp = upsample_average_disp(
            average_disp, frame_down_factor, frame_shape, values)

        # run the filter
        foveal = Foveal(average_disp, frame_down_factor, mem_down_factor,
                        fovea_shape, frame_shape, values,
                        iters=iters, fovea_levels=fovea_levels, **args)
        disp, _ = foveal.process_frame(frame_ten)

        # cost = cost_on_points(disp[:,values:], true_points, full_shape=full_shape)
        cost = cost_on_points(disp[:,values:], true_points, average_disp,
                              full_shape=full_shape, clip=error_clip)

        costs.append(cost)

    error = np.mean(costs)

    errors[arg_key(args)] = error
    args_s = "{%s}" % ', '.join("%r: %s" % (k, args[k]) for k in sorted(space))
    print("%s: %s" % (error, args_s))
    return error
示例#2
0
full_values = 128
frame_down_factor = 1

assert full_values % 2**frame_down_factor == 0
values = full_values / 2**frame_down_factor


sources = []
# for index in range(1):
# for index in range(30):
for index in range(194):
    source = KittiMultiViewSource(index, test=False)
    frame_ten = [downsample(source.frame_ten[0], frame_down_factor),
                 downsample(source.frame_ten[1], frame_down_factor)]
    true_points = source.get_ground_truth_points(occluded=False)

    sources.append((source, frame_ten, true_points))


r = np.log(10)
space = collections.OrderedDict([
    ('laplacian_ksize', pyll.scope.int(1 + hp.quniform('laplacian_ksize', 0, 20, 2))),
    ('laplacian_scale', hp.lognormal('laplacian_scale', 0, r)),
    ('data_weight', hp.lognormal('data_weight', -2*r, r)),
    ('data_max', hp.lognormal('data_max', 2*r, r)),
    ('data_exp', hp.lognormal('data_exp', 0, r)),
    ('disc_max', hp.lognormal('disc_max', r, r)),
    ('smooth', hp.lognormal('smooth', 0, r)),
    ('post_smooth', hp.lognormal('post_smooth', 0, r)),
])
示例#3
0
full_values = 128
frame_down_factor = 1

assert full_values % 2**frame_down_factor == 0
values = full_values / 2**frame_down_factor

sources = []
# for index in range(1):
# for index in range(30):
for index in range(194):
    source = KittiMultiViewSource(index, test=False)
    frame_ten = [
        downsample(source.frame_ten[0], frame_down_factor),
        downsample(source.frame_ten[1], frame_down_factor)
    ]
    true_points = source.get_ground_truth_points(occluded=False)

    sources.append((source, frame_ten, true_points))

r = np.log(10)
space = collections.OrderedDict([
    ('laplacian_ksize',
     pyll.scope.int(1 + hp.quniform('laplacian_ksize', 0, 20, 2))),
    ('laplacian_scale', hp.lognormal('laplacian_scale', 0, r)),
    ('data_weight', hp.lognormal('data_weight', -2 * r, r)),
    ('data_max', hp.lognormal('data_max', 2 * r, r)),
    ('data_exp', hp.lognormal('data_exp', 0, r)),
    ('disc_max', hp.lognormal('disc_max', r, r)),
    ('smooth', hp.lognormal('smooth', 0, r)),
    ('post_smooth', hp.lognormal('post_smooth', 0, r)),
])
示例#4
0
def rationale():
    """
    Figure that illustrates rationale for fovea approach, i.e. diminishing returns
    with increasing runtime via further iterations at a given downfactor, but
    possibly too-high cost of using lower downfactor.
    """

#    n_frames = 194
    n_frames = 50

    frame_down_factor = 1
    
    source = KittiMultiViewSource(0)
    full_shape = source.frame_ten[0].shape
    frame_shape = downsample(source.frame_ten[0], frame_down_factor).shape

    params = {'data_weight': 0.16145115747533928, 'disc_max': 294.1504935618425, 'data_max': 32.024780646200725, 'laplacian_ksize': 3}

#     iterations = [1, 2, 3]
    iterations = [1, 2, 3, 4, 5, 7, 10, 15]
    mean_coarse_times = []
    mean_coarse_costs = []
    mean_fine_times = []
    mean_fine_costs = []

    for j in range(len(iterations)):
        print(str(iterations[j]) + ' iterations')
        coarse_times = []
        coarse_costs = []
        fine_times = []
        fine_costs = []

        for i in range(n_frames):
            print(' frame ' + str(i))

            source = KittiMultiViewSource(i)
            true_points = source.get_ground_truth_points(occluded=False)

            frame_down_factor = 1

            coarse_time, coarse_cost = _evaluate_frame(source.frame_ten, true_points, frame_shape,
                    full_shape, frame_down_factor+1, frame_down_factor, iterations[j], params)
            fine_time, fine_cost = _evaluate_frame(source.frame_ten, true_points, frame_shape,
                    full_shape, frame_down_factor+0, frame_down_factor, iterations[j], params)

            coarse_times.append(coarse_time)
            coarse_costs.append(coarse_cost)
            fine_times.append(fine_time)
            fine_costs.append(fine_cost)

        mean_coarse_times.append(np.mean(coarse_times))
        mean_coarse_costs.append(np.mean(coarse_costs))
        mean_fine_times.append(np.mean(fine_times))
        mean_fine_costs.append(np.mean(fine_costs))

    print(mean_coarse_times)
    print(mean_coarse_costs)
    print(mean_fine_times)
    print(mean_fine_costs)

    plt.plot(mean_coarse_times, mean_coarse_costs, color='k', marker='s', markersize=12)
    plt.plot(mean_fine_times, mean_fine_costs, color='k', marker='o', markersize=12)
    plt.xlabel('Runtime (s)', fontsize=18)
    plt.ylabel('Mean absolute disparity error (pixels)', fontsize=18)
    plt.gca().tick_params(labelsize='18')
    plt.show()
示例#5
0
def rationale():
    """
    Figure that illustrates rationale for fovea approach, i.e. diminishing returns
    with increasing runtime via further iterations at a given downfactor, but
    possibly too-high cost of using lower downfactor.
    """

    #    n_frames = 194
    n_frames = 50

    frame_down_factor = 1

    source = KittiMultiViewSource(0)
    full_shape = source.frame_ten[0].shape
    frame_shape = downsample(source.frame_ten[0], frame_down_factor).shape

    params = {
        'data_weight': 0.16145115747533928,
        'disc_max': 294.1504935618425,
        'data_max': 32.024780646200725,
        'laplacian_ksize': 3
    }

    #     iterations = [1, 2, 3]
    iterations = [1, 2, 3, 4, 5, 7, 10, 15]
    mean_coarse_times = []
    mean_coarse_costs = []
    mean_fine_times = []
    mean_fine_costs = []

    for j in range(len(iterations)):
        print(str(iterations[j]) + ' iterations')
        coarse_times = []
        coarse_costs = []
        fine_times = []
        fine_costs = []

        for i in range(n_frames):
            print(' frame ' + str(i))

            source = KittiMultiViewSource(i)
            true_points = source.get_ground_truth_points(occluded=False)

            frame_down_factor = 1

            coarse_time, coarse_cost = _evaluate_frame(source.frame_ten,
                                                       true_points,
                                                       frame_shape, full_shape,
                                                       frame_down_factor + 1,
                                                       frame_down_factor,
                                                       iterations[j], params)
            fine_time, fine_cost = _evaluate_frame(source.frame_ten,
                                                   true_points, frame_shape,
                                                   full_shape,
                                                   frame_down_factor + 0,
                                                   frame_down_factor,
                                                   iterations[j], params)

            coarse_times.append(coarse_time)
            coarse_costs.append(coarse_cost)
            fine_times.append(fine_time)
            fine_costs.append(fine_cost)

        mean_coarse_times.append(np.mean(coarse_times))
        mean_coarse_costs.append(np.mean(coarse_costs))
        mean_fine_times.append(np.mean(fine_times))
        mean_fine_costs.append(np.mean(fine_costs))

    print(mean_coarse_times)
    print(mean_coarse_costs)
    print(mean_fine_times)
    print(mean_fine_costs)

    plt.plot(mean_coarse_times,
             mean_coarse_costs,
             color='k',
             marker='s',
             markersize=12)
    plt.plot(mean_fine_times,
             mean_fine_costs,
             color='k',
             marker='o',
             markersize=12)
    plt.xlabel('Runtime (s)', fontsize=18)
    plt.ylabel('Mean absolute disparity error (pixels)', fontsize=18)
    plt.gca().tick_params(labelsize='18')
    plt.show()