def generate_new_imgs()

in one_shot_domain_adaptation.py [0:0]


def generate_new_imgs(opt, g_mapping, g_synthesis, latents_numpy):
    """Generate new images based on optimized model and style mixing."""
    # load latent numpy
    latents = Variable(torch.from_numpy(latents_numpy).cuda())
    if not opt.randomize_seed:
        torch.manual_seed(20)
    for i in range(0, opt.how_many_samples):
        with torch.no_grad():
            rand_z = torch.randn(1, 512).cuda()
            rand_latents = g_mapping.forward(rand_z)

            latents[:, : opt.how_many_layers, :] = rand_latents[
                                                   :, : opt.how_many_layers, :
                                                   ]
            imgs = g_synthesis.forward(latents)
            imgs = (imgs.clamp(-1, 1) + 1) / 2.0  # normalization to 0..1 range

        res_img = imgs.cpu().float().numpy()
        # reshape from batchxcxhxw to batchxhxwxc and scale to [0, 255].
        res_img = (np.transpose(res_img, (0, 2, 3, 1)) + 1) / 2.0 * 255.0

        logging.info(
            "generating {0}/{1:06d}_synthesized.jpg".format(opt.output_folder, i)
        )
        imageio.imsave(
            "{0}/{1:06d}_synthesized.jpg".format(opt.output_folder, i), res_img[0]
        )