def generate_fake_images()

in one_shot_domain_adaptation.py [0:0]


def generate_fake_images(opt, generator, landmarks_det_68):
    """Generate fake images from real images. We read the images line by line until
    it forms a batch of images, which is given to the trained StyeGAN model to infer
    the latent code and regenerate the image. It is then post-processed to blend the
    face with the original image."""
    # ----------------------------------------------------------------------
    # Rotate and rectify images of the given batch.
    # ----------------------------------------------------------------------
    rotated_img_256_batch = []
    img_names = []
    # for src_img, img_name in zip(src_imgs, img_names):
    src_img = read_image_to_numpy(opt.img_name)

    img_name_no_extension = ".".join(os.path.basename(opt.img_name).split(".")[:-1])
    img_names.append(img_name_no_extension)
    if opt.no_crop_and_rotate:
        rotated_img_256 = scipy.misc.imresize(src_img, (256, 256))
        imageio.imsave(
            "{}/{}_rotated.png".format(opt.output_folder, img_name_no_extension),
            rotated_img_256,
        )
        rotated_img_256 = (rotated_img_256 - 127.5) / 127.5
        rotated_img_256 = np.rollaxis(rotated_img_256, 2, 0)
        rotated_img_256 = np.expand_dims(rotated_img_256, 0)
    else:
        rotated_img_256 = crop_and_rotate_img(
            opt, src_img, landmarks_det_68, img_name_no_extension
        )
    if rotated_img_256 is None:
        logging.info('No face detected.')
        exit()
    rotated_img_256_batch.append(rotated_img_256)

    # ----------------------------------------------------------------------
    # Infer the latent style and regenerate the image.
    # ----------------------------------------------------------------------
    rotated_img_256_batch = np.vstack(rotated_img_256_batch)
    rotated_img_256_batch = Variable(
        torch.from_numpy(rotated_img_256_batch).float().cuda()
    )

    generator, latents_numpy = regenerate_img(
        opt, rotated_img_256_batch, generator, exp_img_batch=None, img_names=img_names
    )  # generated images are 1024 x 1024.
    return generator, latents_numpy