def make_rbm2(Q, args): if os.path.isdir(args.rbm2_dirpath): print("\nLoading RBM #2 ...\n\n") rbm2 = BernoulliRBM.load_model(args.rbm2_dirpath) else: print("\nTraining RBM #2 ...\n\n") epochs = args.epochs[1] n_every = args.increase_n_gibbs_steps_every n_gibbs_steps = np.arange(args.n_gibbs_steps[1], args.n_gibbs_steps[1] + epochs / n_every) learning_rate = args.lr[1] / np.arange(1, 1 + epochs / n_every) n_gibbs_steps = np.repeat(n_gibbs_steps, n_every) learning_rate = np.repeat(learning_rate, n_every) rbm2 = BernoulliRBM( n_visible=args.n_hidden[0], n_hidden=args.n_hidden[1], W_init=args.w_init[1], vb_init=args.vb_init[1], hb_init=args.hb_init[1], n_gibbs_steps=n_gibbs_steps, learning_rate=learning_rate, momentum=args.momentum, max_epoch=max(args.epochs[1], n_every), batch_size=args.batch_size[1], l2=args.l2[1], sample_h_states=True, sample_v_states=True, sparsity_cost=0., dbm_last=True, # !!! metrics_config=dict( msre=True, pll=True, train_metrics_every_iter=500, ), verbose=True, #display_filters=0, #display_hidden_activations=24, random_seed=args.random_seed[1], v_shape=(20, 20), # what's the v_shape in this case? freeze_weights=args.freeze_weights, prune=args.prune, #filter_shape = (10,10), #,args.filter_shape[1], dtype='float32', tf_saver_params=dict(max_to_keep=1), model_path=args.rbm2_dirpath) #run on cpu config = tf.ConfigProto(device_count={'GPU': 0}) rbm2._tf_session_config = config rbm2.fit(Q) return rbm2
def make_rbm1(X, args): if os.path.isdir(args.rbm1_dirpath): print("\nLoading RBM #1 ...\n\n") rbm1 = BernoulliRBM.load_model(args.rbm1_dirpath) else: print("\nTraining RBM #1 ...\n\n") if not hasattr(args, 'double_rf'): args.double_rf = False rbm1 = BernoulliRBM( n_visible=args.n_vis, n_hidden=args.n_hidden[0], W_init=args.w_init[0], vb_init=args.vb_init[0], hb_init=args.hb_init[0], n_gibbs_steps=args.n_gibbs_steps[0], learning_rate=args.lr[0], momentum=args.momentum, max_epoch=args.epochs[0], batch_size=args.batch_size[0], l2=args.l2[0], sample_h_states=True, sample_v_states=True, sparsity_cost=0., dbm_first=True, # !!! metrics_config=dict( msre=True, pll=True, train_metrics_every_iter=500, ), verbose=True, #display_filters=30, #display_hidden_activations=24, v_shape=args.v_shape, freeze_weights=args.freeze_weights, prune=args.prune, filter_shape=args.filter_shape[0], double_rf=args.double_rf, random_seed=args.random_seed[0], dtype='float32', tf_saver_params=dict(max_to_keep=1), model_path=args.rbm1_dirpath) #run on cpu config = tf.ConfigProto(device_count={'GPU': 0}) rbm1._tf_session_config = config rbm1.fit(X) return rbm1
def make_rbm2(Q, args): if os.path.isdir(args.rbm2_dirpath): print("\nLoading RBM #2 ...\n\n") rbm2 = BernoulliRBM.load_model(args.rbm2_dirpath) else: print("\nTraining RBM #2 ...\n\n") epochs = args.epochs[1] n_every = args.increase_n_gibbs_steps_every n_gibbs_steps = np.arange(args.n_gibbs_steps[1], args.n_gibbs_steps[1] + epochs / n_every) learning_rate = args.lr[1] / np.arange(1, 1 + epochs / n_every) n_gibbs_steps = np.repeat(n_gibbs_steps, n_every) learning_rate = np.repeat(learning_rate, n_every) rbm2 = BernoulliRBM(n_visible=args.n_hiddens[0], n_hidden=args.n_hiddens[1], W_init=0.005, vb_init=0., hb_init=0., n_gibbs_steps=n_gibbs_steps, learning_rate=learning_rate, momentum=[0.5] * 5 + [0.9], max_epoch=max(args.epochs[1], n_every), batch_size=args.batch_size[1], l2=args.l2[1], sample_h_states=True, sample_v_states=True, sparsity_cost=0., dbm_last=True, # !!! metrics_config=dict( msre=True, pll=True, train_metrics_every_iter=500, ), verbose=True, display_filters=0, display_hidden_activations=24, random_seed=args.random_seed[1], dtype='float32', tf_saver_params=dict(max_to_keep=1), model_path=args.rbm2_dirpath) rbm2.fit(Q) return rbm2
def make_rbm1(X, args): if os.path.isdir(args.rbm1_dirpath): print("\nLoading RBM #1 ...\n\n") rbm1 = BernoulliRBM.load_model(args.rbm1_dirpath) else: print("\nTraining RBM #1 ...\n\n") rbm1 = BernoulliRBM(n_visible=784, n_hidden=args.n_hiddens[0], W_init=0.001, vb_init=0., hb_init=0., n_gibbs_steps=args.n_gibbs_steps[0], learning_rate=args.lr[0], momentum=[0.5] * 5 + [0.9], max_epoch=args.epochs[0], batch_size=args.batch_size[0], l2=args.l2[0], sample_h_states=True, sample_v_states=True, sparsity_cost=0., dbm_first=True, # !!! metrics_config=dict( msre=True, pll=True, train_metrics_every_iter=500, ), verbose=True, display_filters=30, display_hidden_activations=24, v_shape=(28, 28), random_seed=args.random_seed[0], dtype='float32', tf_saver_params=dict(max_to_keep=1), model_path=args.rbm1_dirpath) rbm1.fit(X) return rbm1