Exemple #1
0
def get_new_embeddings(input_images, latentgan_model: LatentGAN,
                       confignet_model: ConfigNet):
    '''Samples new embeddings from either:
        - the LatentGAN if no input images were provided
        - by embedding the input images into the latent space using the real encoder
    '''
    if input_images is None:

        embeddings = latentgan_model.generate_latents(1, truncation=0.7)
        rotations = np.zeros((1, 3), dtype=np.float32)
        orig_images = confignet_model.generate_images(embeddings, rotations)
    else:
        sample_indices = np.random.randint(0, len(input_images), 1)
        orig_images = np.array([input_images[x] for x in sample_indices])
        embeddings, rotations = confignet_model.encode_images(orig_images)

    return embeddings, rotations, orig_images
Exemple #2
0
def get_new_embeddings(args, input_images, latentgan_model: LatentGAN, confignet_model: ConfigNet):
    '''Samples new embeddings from either:
        - the LatentGAN if no input images were provided
        - by embedding the input images into the latent space using the real encoder
    '''
    if input_images is None:
        n_samples = args.n_rows * args.n_cols
        embeddings = latentgan_model.generate_latents(n_samples, truncation=0.7)
        rotations = np.zeros((n_samples, 3), dtype=np.float32)
        orig_images = confignet_model.generate_images(embeddings, rotations)
    else:
        # special case for one image so the demo is faster and nicer
        if len(input_images) == 1:
            args.n_rows = 1
            args.n_cols = 1
        n_samples = args.n_rows * args.n_cols
        sample_indices = np.random.randint(0, len(input_images), n_samples)
        orig_images = np.array([input_images[x] for x in sample_indices])
        embeddings, rotations = confignet_model.encode_images(orig_images)

    return embeddings, rotations, orig_images