Exemple #1
0
def objective(args):
    n_epochs = 10
    rho = 0.01
    lamb = 5
    noise_std = 0.2
    hidshape = (50, 50)

    rflen, rate, clip = args
    rfshape = (rflen, rflen)
    clip = (-clip, clip)

    layer = SparseAutoencoder(
        visshape=imshape, hidshape=hidshape, rfshape=rfshape,
        f=noisylif, g=linear)

    train_params = {'rho': rho, 'lamb': lamb, 'noise_std': noise_std}
    trainer = SparseTrainer(layer, **train_params)

    stats = sgd(trainer, patches,
                n_epochs=n_epochs, rate=rate, clip=clip, show=False)

    cost = stats['cost'][-1]

    filename = 'results/layer_opt_vh_cost=%0.3e.npz' % cost
    layer.to_file(filename)

    return cost
Exemple #2
0
    linear = Linear(slope=1.0)
    noisylif = NoisyLIFApprox(
        tRef=0.02, tauRC=0.06, alpha=10.0, xint=-0.5, amp=1./41, sigma=0.05)

    layer = SparseAutoencoder(visshape=imshape, hidshape=(50,50),
                              rfshape=(11,11), f=noisylif, g=linear)

    # train_params = {'rho': 0.01, 'lamb': 25, 'noise_std': 0.2}
    # train_params = {'rho': 0.01, 'lamb': 5, 'noise_std': 0.2}
    train_params = {'rho': 0.05, 'lamb': 5, 'noise_std': 0.2}
    trainer = SparseTrainer(layer, **train_params)

    plt.figure(101)
    raw_input("Please place the figure...")

    sgd(trainer, patches, n_epochs=30, rate=0.05, vlims=(-2,2))

    if 'filename' in locals():
        layer.to_file(filename)

else:
    layer = deepnet.CacheObject.from_file(filename)
    print "loaded layer from file: %s" % filename

### untied training
if 1:
    if layer.tied:
        layer.untie()

    train_params = {'rho': 0.05, 'lamb': 5, 'noise_std': 0}
    trainer = SparseTrainer(layer, **train_params)
Exemple #3
0
    #     tRef=0.02, tauRC=0.06, alpha=10.0, xint=-0.5, amp=1./41, sigma=0.05)
    noisylif = func.NoisyLIFApprox(
        tRef=0.002, tauRC=0.05, alpha=0.7, xint=-0.5, amp=1./50, sigma=0.001)

    layer = auto.SparseAutoencoder(visshape=imshape, hidshape=(70,70),
                                   rfshape=(11,11), f=noisylif, g=linear)

    # train_params = {'rho': 0.01, 'lamb': 25, 'noise_std': 0.2}
    # train_params = {'rho': 0.01, 'lamb': 5, 'noise_std': 0.2}
    train_params = {'rho': 0.05, 'lamb': 5, 'noise_std': 0.2}
    trainer = auto.SparseTrainer(layer, **train_params)

    plt.figure(101)
    raw_input("Please place the figure...")

    auto.sgd(trainer, images, n_epochs=30, rate=0.05, vlims=(-2,2))

    if 'filename' in locals():
        layer.to_file(filename)

else:
    layer = deepnet.CacheObject.from_file(filename)

### test the layer
if 1:
    # test = timages[:200]
    test = timages
    recs = layer.compVHV(test)
    rmse = np.sqrt(((recs - test)**2).mean())
    print "rmse", rmse
Exemple #4
0
                    {'rho': 0.05, 'lamb': 0, 'noise_std': 0.1},
                    {'rho': 0.05, 'lamb': 0, 'noise_std': 0.0}]

    for i, layer in enumerate(net.layers):
        sgd_param = sgd_params[i]
        train_param = train_params[i]

        # subtract completed epochs
        sgd_param['n_epochs'] -= algo_epochs(layer, 'sgd')
        if sgd_param['n_epochs'] > 0:
            trainer = auto.SparseTrainer(layer, **train_param)
            test_fn = net.propVHV_fn(maxlayer=i)
            # save_fn = lambda: net.to_file(loadfile)
            save_fn = None
            auto.sgd(trainer, images, timages, test_fn=test_fn,
                     vlims=(-2,2), save_fn=save_fn,
                     **sgd_param)

            if save_fn is None:
                # net.to_file(loadfile)
                layer_file = "%s.layer_%d_%s.npz" % (
                        loadfile, i,
                        datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S"))
                layer.to_file(layer_file)

        images = layer.compup(images)

    net.to_file(loadfile)

if 1:
    results = net.compVHV(patches)
Exemple #5
0
    # layer = SparseAutoencoder(visshape=imshape, hidshape=(50,50),
    #                           rfshape=(9,9), f=noisylif, g=linear)
    layer = SparseAutoencoder(visshape=imshape, hidshape=(40,40),
                              rfshape=(9,9), f=noisylif, g=linear)

    if loadfile is not None:
        layer.tofile(loadfile)
else:
    layer = deepnet.CacheObject.fromfile(loadfile)

################################################################################
train_params = {'rho': 0.01, 'lamb': 25, 'noise_std': 0.2}
trainer = SparseTrainer(layer, **train_params)

sgd(trainer, images, nepochs=30, rate=0.05)

if 0:
    ### untied training
    sgd(trainer, images, nepochs=1, rate=0.05)
    layer.untie()

    trainer = SparseTrainer(layer, **train_params)
    sgd(trainer, images, nepochs=30, rate=0.05)

results = layer.compVHV(images)

plt.figure(1)
plt.clf()
deepnet.image_tools.compare([images, results], vlims=(-1,1))