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) lbfgs(trainer, patches, n_evals=30, vlims=(-2,2)) ### test the layer if 1: test = patches[:100] recs = layer.compVHV(test) rmse = np.sqrt(((recs - test)**2).mean()) print "rmse", rmse plt.figure(1) plt.clf() deepnet.image_tools.compare([test, recs], vlims=(-2,2))
# 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))