vis_samples = [None] * nb_interp for x in range(nb_interp): column = np.empty(shape=(nb_interp, 3, 64, 64), dtype=np.float32) for y in range(nb_interp): # 3D interpolation cx = x / (nb_interp) cy = y / (nb_interp) cz = z / (nb_interp) z_mv1 = n1a * (1 - cx) + n1b * (cx) z_mv2 = n2a * (1 - cy) + n2b * (cy) z_mv3 = n3a * (1 - cz) + n3b * (cz) # get sample f_image, _ = netG(z_list=[z_mv1, z_mv2, z_mv3]) np_fake = to_numpy(f_image) column[y] = np_fake vis_samples[x] = column # save images png_file = '3Dinterp__text=%dto%d__shape=%dto%d__background=%dto%d-%d.png' % \ (mv1_ida, mv1_idb, mv2_ida, mv2_idb, mv3_ida, mv3_idb, z) save_images(vis_samples, save=not sample_folder == '', save_path=os.path.join(sample_folder, png_file), dim_ordering='th') print('Images saved at %s' % sample_folder)
netEb = netEb.cuda() # # get batch of test samples images, _, segs, txt_data, txt_len, captions, *_ = next(iter(dataloader)) images = images.cuda() segs = segs.cuda() txt_data = txt_data.cuda() bimages = images netG.eval() netEs.eval() netEb.eval() # bimages = roll(images, i+1, dim=0) # for text and seg mismatched backgrounds np_bimages = to_numpy(bimages) np_segs = np.repeat(to_numpy(segs), 3, 1) * 2 - 1 n = 4 vis_samples = [None for i in range(1 + n)] vis_samples[0] = np_segs for i in range(n): # generate testing results segs_code = netEs(segs) bkgs_code = netEb(bimages[i].unsqueeze(0).repeat(batch_size, 1, 1, 1)) *_, f_images, z_list = netG(txt_data, txt_len, segs_code, bkgs_code) np_fakes = to_numpy(f_images)
# alignment if align == 'shape': bimages = roll(images, 2, dim=0) # for text and seg mismatched backgrounds bsegs = roll(segs, 2, dim=0) # for text and seg mismatched backgrounds elif align == 'background': segs = roll(segs, 1, dim=0) # for text mismatched segmentations elif align == 'all': bimages = images.clone() bsegs = segs.clone() elif align == 'none': bimages = roll(images, 2, dim=0) # for text and seg mismatched backgrounds segs = roll(segs, 1, dim=0) # for text mismatched segmentations bsegs = roll(segs, 2, dim=0) # for text and seg mismatched backgrounds np_segs = to_numpy(segs) np_bsegs = to_numpy(bsegs) np_images = to_numpy(images) np_bimages = to_numpy(bimages) segs_code = netEs(segs) bkgs_code = netEb(bimages) *_, f_images, z_list = netG(txt_data, txt_len, segs_code, bkgs_code) np_fakes = to_numpy(f_images) for x, b, s, sb in zip(np_fakes, np_bimages, np_segs, np_bsegs): x = (x.transpose(1,2,0) + 1)/2. * 255. b = (b.transpose(1,2,0) + 1)/2. * 255. s = s.transpose(1,2,0)