# train obj_class += model.pretraining_class(sess, batch_figs, batch_labels) obj_disc += model.pretraining_disc(sess, batch_figs, batch_labels, batch_z) obj_vae += model.pretraining_vae(sess, batch_figs, batch_labels) obj_dec += model.pretraining_dec(sess, batch_figs, batch_labels, batch_z) if step % 10 == 0: print(' step {}/{} end'.format(step, num_one_epoch)) sys.stdout.flush() tmp_z = model.encoding(sess, batch_figs, batch_labels) tmp_figs = model.gen_fig(sess, batch_labels, tmp_z) dump_figs(np.asarray(tmp_figs), 'sample_result') print('epoch:{}, v_obj = {}, dec_obj = {}, disc_obj = {}'.format( epoch, obj_vae / num_one_epoch, obj_dec / num_one_epoch, obj_disc / num_one_epoch)) saver.save(sess, './model.dump') # -- main training --------------- for epoch in range(epoch_num): epoch_figs, epoch_labels = shuffle(figs, labels) print('** epoch {} begin **'.format(epoch)) obj_class, obj_vae, obj_dec, obj_disc = 0.0, 0.0, 0.0, 0.0 for step in range(num_one_epoch):
def __call__(self, z_inputs): assert(len(z_inputs) == self.batch_size) return self.model.gen_fig(self.sess, z_inputs) if __name__ == u'__main__': # dump file dump_file = u'./model.dump' # parameter batch_size = 1 z_dim = 100 # figure generator fig_gen = FigGenerator(dump_file, z_dim, batch_size) # make figure fig1 = cv2.imread('./input1.jpg') fig1 = fig1/127.5 - 1.0 fig2 = cv2.imread('./input2.jpg') fig2 = fig2/127.5 - 1.0 z1 = fig_gen.encoding([fig1])[0] z2 = fig_gen.encoding([fig2])[0] diff = (z2 - z1)/50.0 zs = [] for i in range(51): z_target = z1 + diff * float(i) zs.append(fig_gen([z_target])[0]) dump_figs(np.asarray(zs), 'morphing_result')