Beispiel #1
0
def get_rfs(inputs, voxels, mods, approx_n = GRAD_APPROX_N):
    manager, grads = backprop_fields.gradients_raw_fullbatch(
        model, inputs, voxels, mods = mods,
        approx_n = approx_n)
    estimated = backprop_fields.parameter_estimates_grads(grads, voxels)
    params = estimates_to_params(estimated)
    return manager, grads, params
Beispiel #2
0
    full.to_csv(filename)


def load_bbox_csv(filename):
    df = pd.read_csv(filename)
    voxels = vx.VoxelIndex.from_serial(df['unit'])

    bboxes = {}
    layer_strs = map(df['unit'], lambda s: s.split(';')[1])
    for l_str, group in df.groupby(layer_strs):
        layer = tuple(int(i) for i in l_str.split('.'))
        # bboxes[layer] is expected to have shape ([left, top, w, h], n_vox)
        bboxes[layer] = group[['x', 'y', 'var', 'amp']].as_matrix()

    return bboxes


if __name__ == '__main__':

    model, ckpt = cornet.load_cornet("Z")
    inputs = backprop_fields.noise_video(11, 3, 256, 256, numpy=False)
    manager = nm.NetworkManager.assemble(model, inputs)

    voxel = {(0, 1, 0): vx.VoxelIndex((0, 1, 0), ([1], [50], [30]))}
    _, grads = backprop_fields.gradients_raw_fullbatch(model, inputs, voxel)
    rfbb = trace_rf(sequential_leaves(manager, stop=(0, 1, 0)), manager)

    rfbb = (30 * rfbb[0][1] - rfbb[1][1], 50 * rfbb[0][0] - rfbb[1][0],
            rfbb[1][1] * 2 + 1, rfbb[1][0] * 2 + 1)
    backprop_fields.grad_plot(grads, [(0, 1, 0)], 0, 0, bbox=rfbb)
Beispiel #3
0
        video_gen.rf_slider_check(frame, check_widths=[50, 30, 5], speed=8),
        'color':
        video_gen.color_rotation(frame, 128),
        'orientation':
        video_gen.sine_rotation(frame, 64, freqs=[5, 20])
    }

    # ---- Compute Receptive fields, etc. ----

    results = {}
    for k, inp in inputs.items():
        manager = nm.NetworkManager.assemble(model, inp)
        bboxes = possible_fields.rf_bboxes(voxels, manager)

        print("\n[ Gradients: {} ]".format(k))
        _, grads = bf.gradients_raw_fullbatch(model, inp, voxels, approx_n=30)
        params = bf.parameter_estimates_grads(grads, voxels)

        true_acts, pred_acts = lsq_fields.voxel_activity(
            voxels, manager, inp.numpy(), params)
        results[k] = {
            'grad': grads,
            'params': params,
            'true_acts': true_acts,
            'pred_acts': pred_acts,
        }

    # ---- Saving & Plotting RF Diagnostics ----

    print("Saving and Plotting")