def train_model1(sess, train_op, n_epoch, opt, model1, X_dataset, Y_dataset, Z_dataset, qvars, pvars, dvars, qvars_y, pvars_y, dvars_y): train_gen_op_x = train_op.get_train_gen_op_x() train_disc_op_x = train_op.get_train_disc_op_x() train_gen_op_y = train_op.get_train_gen_op_y() train_disc_op_y = train_op.get_train_disc_op_y() x = model1.get_x() y = model1.get_y() z = model1.get_z() d1 = model1.get_d1() d2 = model1.get_d2() FG_x = [] FG_y = [] FD_x = [] FD_y = [] DG_xz = DG() DG_xz.initial() DG_yz = DG() DG_yz.initial() dmb1 = [[1]*2]*128 dmb2 = [[0]*2]*128 for epoch in tqdm( range(n_epoch), total=n_epoch): X_dataset = shuffle(X_dataset) Y_dataset = shuffle(Y_dataset) Z_dataset = shuffle(Z_dataset) i = 0 #print(dmb) for xmb, ymb, zmb in iter_data(X_dataset, Y_dataset, Z_dataset, size=batch_size): #print(xmb) i = i + 1 for _ in range(1): f_d_x, _ = sess.run([model1.get_disc_loss_x(), train_disc_op_x], feed_dict={x: xmb, y:ymb, z:zmb, d1:dmb1, d2:dmb2}) for _ in range(5): f_g_x, _ = sess.run([[model1.get_gen_loss_x(), model1.get_gen_loss_xz(), model1.get_cost_x(), model1.get_cost_xz()], train_gen_op_x], feed_dict={x: xmb, y:ymb, z:zmb, d1:dmb1, d2:dmb2}) FG_x.append(f_g_x) FD_x.append(f_d_x) for _ in range(1): f_d_y, _ = sess.run([model1.get_disc_loss_y(), train_disc_op_y], feed_dict={x: xmb, y:ymb, z:zmb, d1:dmb1, d2:dmb2}) for _ in range(5): f_g_y, _ = sess.run([[model1.get_gen_loss_y(), model1.get_gen_loss_yz(), model1.get_cost_y(), model1.get_cost_yz()], train_gen_op_y], feed_dict={x: xmb, y:ymb, z:zmb, d1:dmb1, d2:dmb2}) FG_y.append(f_g_y) FD_y.append(f_d_y) print_xz(epoch, i, f_d_x, f_g_x[0], f_g_x[1], f_g_x[2], f_g_x[3]) print_yz(epoch, i, f_d_y, f_g_y[0], f_g_y[1], f_g_y[2], f_g_y[3]) DG_xz.set_FD(FD_x) DG_xz.set_FG(FG_x) DG_yz.set_FD(FD_y) DG_yz.set_FG(FG_y) return sess, DG_xz, DG_yz, model1
def train_model2(train_op, n_epoch_2, opt, model1, sess, X_dataset, Y_dataset, W_dataset, Z_dataset): train_gen_op_xyw = train_op.get_train_gen_op_xyw() train_disc_op_xyw = train_op.get_train_disc_op_xyw() FD_xyw = [] FG_xyw = [] DG_xyw = DG() DG_xyw.initial() dmb1 = [[0]*2]*128 dmb2 = [[1]*2]*128 x = model1.get_x() y = model1.get_y() w = model1.get_w() z = model1.get_z() d1 = model1.get_d1() d2 = model1.get_d2() for epoch in tqdm( range(n_epoch_2), total=n_epoch_2): X_dataset = shuffle(X_dataset) Y_dataset = shuffle(Y_dataset) W_dataset = shuffle(W_dataset) Z_dataset = shuffle(Z_dataset) i = 0 for xmb, ymb, wmb, zmb in iter_data(X_dataset, Y_dataset, W_dataset, Z_dataset, size=batch_size): i = i + 1 for _ in range(1): f_d_xyw, _ = sess.run([model1.get_disc_loss_xyw(), train_disc_op_xyw], feed_dict={x: xmb, y:ymb, w:wmb, z:zmb, d1:dmb1, d2:dmb2}) for _ in range(5): f_g_xyw, _ = sess.run([[model1.get_gen_loss_xyw(), model1.get_gen_loss_x(), model1.get_cost_x(), model1.get_cost_xz()], train_gen_op_xyw], feed_dict={x: xmb, y:ymb, w:wmb, z:zmb, d1:dmb1, d2:dmb2}) FG_xyw.append(f_g_xyw) FD_xyw.append(f_d_xyw) print_xy(epoch, i, f_d_xyw, f_g_xyw[0], f_g_xyw[1], f_g_xyw[2], f_g_xyw[3]) DG_xyw.set_FD(FD_xyw) DG_xyw.set_FG(FG_xyw) return sess, DG_xyw, model1
}) for _ in range(5): f_g_y, _ = sess.run( [[gen_loss_y, gen_loss_yz, cost_y, cost_yz], train_gen_op_y], feed_dict={ x: xmb, y: ymb, z: zmb }) FG_y.append(f_g_y) FD_y.append(f_d_y) print_xz(epoch, i, f_d_x, f_g_x[0], f_g_x[1], f_g_x[2], f_g_x[3]) print_yz(epoch, i, f_d_y, f_g_y[0], f_g_y[1], f_g_y[2], f_g_y[3]) DG_xz.set_FD(FD_x) DG_xz.set_FG(FG_x) DG_yz.set_FD(FD_y) DG_yz.set_FG(FG_y) q_xz = x_inference_network(x, latent_dim, n_layer_inf, n_hidden_inf, eps_dim) p_y = y_generative_network(q_xz, input_dim, n_layer_gen, n_hidden_gen, eps_dim) q_yz = y_inference_network(y, latent_dim, n_layer_inf, n_hidden_inf, eps_dim) p_x = x_generative_network(q_yz, input_dim, n_layer_gen, n_hidden_gen, eps_dim) decoder_logit_x = x_data_network(x, q_xz, n_layers=n_layer_disc, n_hidden=n_hidden_disc) encoder_logit_x = y_data_network(p_y, q_xz,