# 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) rmses = imtools.rmse(patches, results) print "rmse", rmses.mean(), rmses.std() if imtools.display_available(): plt.figure(figsize=(11.925, 12.425)) imtools.compare([patches, results], rows=8, cols=12, vlims=(-2,2))
# 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 plt.figure(1) plt.clf() imtools.compare([test, recs], vlims=(-2,2))