rbmobject1.restore_weights('./out/rbmw1.chp') rbmobject2.restore_weights('./out/rbmw2.chp') iterations = len(trX) / FLAGS.batchsize # Train First RBM print 'first rbm: ', FLAGS.epochs, ' epochs of ', iterations, ' iterations' for i in range(FLAGS.epochs): print 'epoch=', i for j in range(iterations): batch_xs, batch_ys = mnist.train.next_batch(FLAGS.batchsize) _, batch_err = rbmobject1.partial_fit(batch_xs) rbmobject1.save_weights('./out/rbmw1.chp') save_image("out/1rbm.jpg", rbmobject1.n_w.T, (28, 28), (100, 100)) show_image("out/1rbm.jpg") rbmobject1.end_training() # # Train Second RBM rbmobject1.restore_weights('./out/rbmw1.chp') # improves init w1 = rbmobject1.getOWeight() rbmobject2.setOWeight(np.transpose(w1)) print 'second rbm: ', FLAGS.epochs, ' epochs of ', iterations, ' iterations' for i in range(FLAGS.epochs): print 'epoch=', i for j in range(iterations): batch_xs, batch_ys = mnist.train.next_batch(FLAGS.batchsize) # Transform features with first rbm for second rbm batch_xs = rbmobject1.sample_v2h(batch_xs) _, batch_err = rbmobject2.partial_fit(batch_xs) rbmobject2.save_weights('./out/rbmw2.chp')