コード例 #1
0
        regions = np.array(bb_to_seg(gen_bbs))[0, :, :, :].transpose((1, 2, 0))
        graph = [real_nodes, None]

        if k == 0:
            graph_arr = draw_graph([real_nodes, eds.detach().cpu().numpy()])
            final_images.append(graph_arr)

#             # place real
#             real_bbs = real_bbs[np.newaxis, :, :]/32.0
#             real_im = bb_to_im_fid(real_bbs, real_nodes)
#             final_images.append(real_im)

# reconstruct
        fake_im_seg = draw_masks(gen_mks, real_nodes)
        final_images.append(fake_im_seg)
        fake_im_bb = bb_to_im_fid(gen_bbs, real_nodes,
                                  im_size=256).convert('RGBA')
        final_images.append(fake_im_bb)
    n_rows += 1
    if (n_rows + 1) % 12 == 0:
        final_images_new = []
        for im in final_images:
            print(np.array(im).shape)
            final_images_new.append(
                torch.tensor(np.array(im).transpose((2, 0, 1))) / 255.0)

        # print('final: ', final_images_new[0].shape)
        final_images = final_images_new
        final_images = torch.stack(final_images)
        print(final_images)
        save_image(final_images,
                   "./output/results_page_{}_{}.png".format(
コード例 #2
0
                [np.array(mask_to_bb(mk)) for mk in gen_mks.detach().cpu()])
            real_bbs = np.array(
                [np.array(mask_to_bb(mk)) for mk in real_mks.detach().cpu()])
            real_nodes = np.where(given_nds.detach().cpu() == 1)[-1]
        gen_bbs = gen_bbs[np.newaxis, :, :] / 32.0
        junctions = np.array(bb_to_vec(gen_bbs))[0, :, :]
        regions = np.array(bb_to_seg(gen_bbs))[0, :, :, :].transpose((1, 2, 0))
        graph = [real_nodes, None]

        if k == 0:
            graph_arr = draw_graph([real_nodes, eds.detach().cpu().numpy()])
            final_images.append(graph_arr)

            # place real
            real_bbs = real_bbs[np.newaxis, :, :] / 32.0
            real_im = bb_to_im_fid(real_bbs, real_nodes)
            final_images.append(real_im)

        # reconstruct
        fake_im = draw_masks(gen_mks, real_nodes)
        #         fake_im = bb_to_im_fid(gen_bbs, real_nodes)
        final_images.append(fake_im)

row = 0
for k, im in enumerate(final_images):
    path = './out/var_{}/'.format(row)
    os.makedirs(path, exist_ok=True)
    im.save('{}/{}.png'.format(path, k))
    if (k + 1) % 12 == 0:
        row += 1
# final_images = torch.stack(final_images).transpose(1, 3)
コード例 #3
0
    # Unpack batch
    mks, nds, eds, nd_to_sample, ed_to_sample = batch

    # Configure input
    real_mks = Variable(mks.type(Tensor))
    given_nds = Variable(nds.type(Tensor))
    given_eds = eds
    for k in range(opt.num_variations):
        # plot images
        z = Variable(
            Tensor(np.random.normal(0, 1,
                                    (real_mks.shape[0], opt.latent_dim))))
        with torch.no_grad():
            gen_mks = generator(z, given_nds, given_eds.cuda())
            gen_bbs = np.array(
                [np.array(mask_to_bb(mk)) for mk in gen_mks.detach().cpu()])
            real_bbs = np.array(
                [np.array(mask_to_bb(mk)) for mk in real_mks.detach().cpu()])
            real_nodes = np.where(given_nds.detach().cpu() == 1)[-1]

        if k == 0:
            real_bbs = real_bbs[np.newaxis, :, :] / 32.0
            real_im = bb_to_im_fid(real_bbs, real_nodes)
            real_im.save('{}/{}.jpg'.format(path_real, globalIndexReal))
            globalIndexReal += 1

        # draw vector
        gen_bbs = gen_bbs[np.newaxis, :, :] / 32.0
        fake_im = bb_to_im_fid(gen_bbs, real_nodes)
        fake_im.save('{}/{}.jpg'.format(path_fake, globalIndexFake))
        globalIndexFake += 1