def make_GBRBM_kfold(train_data, valid_data, Image_type, k, save_path): ##############% K-fold based restricted boltzmann machine for training # train the model gbrbm = GBRBM(n_visible=train_data.shape[1], n_hidden=1000, learning_rate=0.01, momentum=0.9, use_tqdm=True) train_data, valid_data, data_mean = data_demean(train_data,valid_data) errs, errs_val = gbrbm.fit(train_data, valid_data, n_epoches=640, batch_size=20) foldName = str(k)+'_fold/'+Image_type+'/' createFolder(save_path+foldName) plt.plot(errs) plt.show() plt.savefig(save_path+foldName+'train.png') plt.plot(errs_val) plt.savefig(save_path+foldName+'val.png') plt.show() np.save(save_path+foldName+'data_mean.npy', data_mean) gbrbm.save_weights(filename = save_path+foldName, name = Image_type+'_model')
use_tqdm=False, sample_visible=True, sigma=sigma) gb_n_epoches = 40 gb_batch_size = 128 errs = gbrbm.fit(data_x=input_data, n_epoches=gb_n_epoches, batch_size=gb_batch_size, shuffle=True, verbose=True) gb_filename = 'pretrain_models/gbrbm.ckpt' gb_name = 'rbm' gbrbm.save_weights(filename=gb_filename, name=gb_name) #begin pretraining the first Bernoulli-Bernoulli RBM bb_input_data_1 = gbrbm.transform(input_data) bb_input_data_1 = np.array(bb_input_data_1) #print(bb_input_data_1.shape) bb_n_visible_1 = bb_input_data_1.shape[1] bb_n_hid_1 = 2048 bb_learning_rate_1 = 0.01 bb_momentum_1 = 0.95 bb_err_function_1 = 'mse' bbrbm_1 = BBRBM(n_visible=bb_n_visible_1, n_hidden=bb_n_hid_1, learning_rate=bb_learning_rate_1,