gendis.compile(optimizer=gen_opt, loss='binary_crossentropy') shape = dis.get_input_shape_at(0)[1:] gen_input, real_input = Input(shape), Input(shape) dis2batch = Model([gen_input, real_input], [dis(gen_input), dis(real_input)]) dis.trainable = True dis2batch.compile(optimizer=dis_opt, loss='binary_crossentropy', metrics=['binary_accuracy']) gen_trainner = gendis dis_trainner = dis2batch imsave('{}/real.png'.format(vis_dir), Song.grid_vis_songs(data_generator(25))) vis_Z = code_generator(25) for iteration in range(0, niter): print 'iteration', iteration Z = code_generator(nbatch) gen_img = gen.predict(Z) if iteration < args.boost or iteration % args.k == 0: real_img = data_generator(nbatch) gen_y = np.zeros((nbatch, 1)) real_y = np.ones((nbatch, 1)) d_loss = dis_trainner.train_on_batch([gen_img, real_img], [gen_y, real_y]) print('\tDiscriminator:\t{}'.format(d_loss)) else: y = np.ones((nbatch, 1))
shape = dis.get_input_shape_at(0)[1:] gen_input, real_input = Input(shape), Input(shape) dis2batch = Model([gen_input, real_input], [dis(gen_input), dis(real_input)]) dis.trainable = True dis2batch.compile(optimizer=dis_opt, loss='binary_crossentropy', metrics=['binary_accuracy']) gen_trainner = gendis dis_trainner = dis2batch gh = 2 gw = 7 imsave('{}/real.png'.format(vis_dir), Song.grid_vis_songs(data_generator(gh*gw)[:, :, :, 0], gh=gh, gw=gw)) vis_Z = code_generator(gh*gw) fake_pool = gen.predict(vis_Z) for iteration in range(0, niter): print 'iteration', iteration Z = code_generator(nbatch) gen_img = gen.predict(Z) fake_pool = np.vstack([fake_pool[:nbatch], gen_img]) shuffle_indices = np.random.permutation(len(fake_pool)) fake_pool = fake_pool[shuffle_indices] gen_img = fake_pool[:nbatch] real_img = data_generator(nbatch) gen_y = np.zeros((nbatch, 1)) real_y = np.ones((nbatch, 1))