def train_model(num_steps=-1, disp_interval=1000, save_interval=10000, network_name='cluster_net', max_n=500, batch_size=32, delta_diff=1, delta_max=5): if num_steps == -1: num_steps = np.inf i = 1 while i < num_steps: s1, s2, steps = bh.get_batch(batch_size, max_n) [_, loss] = network.sess.run( [network.train, network.loss], feed_dict={ network.inp_state1: s1, network.inp_state2: s2, network.inp_step: steps, network.inp_delta_diff: delta_diff, network.inp_delta_max: delta_max }) print(i, loss) if i % disp_interval == 0: vh.build_plot('recent', 10, batch_size=batch_size, max_n=max_n) if i % save_interval == 0: network.saver.save(network.sess, './' + network_name + '.ckpt') i += 1
def build_plot(save_name, num_samples, batch_size=32, max_n=5, store_points=False): f, ax = plt.subplots() all_points = [] for i in tqdm.tqdm(list(range(num_samples))): s1, s2, n = bh.get_batch(batch_size, max_n) [e1] = network.sess.run([network.e1], feed_dict={network.inp_state1: s1}) all_points.append(e1) ax.scatter(e1[:, 0], e1[:, 1]) if store_points: all_points = np.concatenate(all_points, axis=0) np.save('./' + save_name + '.npy', all_points) f.savefig('./' + save_name+ '.png')
def train_vae(num_steps=-1, batch_size=32, disp_interval=100, save_interval=10000, network_name='vae_net'): import network as network if num_steps == -1: num_steps = np.inf i = 1 while i < num_steps: images = np.reshape(bh.get_batch(batch_size), [-1, 84, 84, 1]) [_, loss, recon ] = network.sess.run([network.train_op, network.loss, network.mu_x], feed_dict={network.inp_image: images / 255.}) print i, loss if i % disp_interval == 0: vh.display_side_by_side('recent', images[0], recon[0]) if i % save_interval == 0: network.saver.save(network.sess, './' + network_name + '.ckpt') i += 1