def get_image(gen, point):
    images = list(map(lambda x: x.detach(), gen(point)))[1:]
    images = [adjust_dynamic_range(image, (-1, 1), (0, 1)) for image in images]
    images = progressive_upscaling(images)
    images = list(map(lambda x: x.squeeze(dim=0), images))
    image = make_grid(images, nrow=int(ceil(sqrt(len(images)))), padding=0)
    return image.cpu().numpy().transpose(1, 2, 0)
Example #2
0
def main(args):
    """
    Main function for the script
    :param args: parsed command line arguments
    :return: None
    """

    img_file = os.path.join(args.image_path)
    if args.npz_file:
        img = np.load(img_file)
    else:
        img = np.array(Image.open(img_file))
        img = np.expand_dims(img, axis=0).transpose(0, 3, 1, 2)

    img = th.from_numpy(img).float()  # make a tensor out of image

    # progressively downsample the image and save it at the given location
    dim = img.shape[-1]  # gives the highest dimension
    ds_img = img  # start from the highest resolution image
    images = [ds_img]  # original image already in
    while dim > 4:
        ds_img = avg_pool2d(ds_img, kernel_size=2, stride=2)
        images.append(ds_img)
        dim //= 2

    images = progressive_upscaling(list(reversed(images)))

    # save the images:
    for count in range(len(images)):
        imsave(os.path.join(args.out_dir,
                            str(count + 1) + ".png"),
               images[count].squeeze(0).permute(1, 2, 0))
Example #3
0
def get_image(gen, point):
    images = list(map(lambda x: x.detach(), gen(point)))
    images = progressive_upscaling(images)
    images = list(map(lambda x: x.squeeze(dim=0), images))
    image = make_grid(images,
                      nrow=int(ceil(sqrt(len(images)))),
                      normalize=True,
                      scale_each=True)
    return image.cpu().numpy().transpose(1, 2, 0)
def get_image(gen, point):
    images = list(map(lambda x: x.detach(), gen(point)))
    images = [adjust_dynamic_range(image) for image in images]
    images = progressive_upscaling(images)
    # discard 128_x_128 resolution (temporarily)
    images = images[:-2] + images[-1:]
    images = list(map(lambda x: x.squeeze(dim=0), images))
    image = make_grid(images, nrow=int(ceil(sqrt(len(images)))), padding=0)
    return image.cpu().numpy().transpose(1, 2, 0)
Example #5
0
def get_image(gen, point):
    """
    obtain an All-resolution grid of images from the given point
    :param gen: the generator object
    :param point: random latent point for generation
    :return: img => generated image
    """
    images = list(map(lambda x: x.detach(), gen(point)))[1:]
    images = [adjust_dynamic_range(image) for image in images]
    images = progressive_upscaling(images)
    images = list(map(lambda x: x.squeeze(dim=0), images))
    image = make_grid(images, nrow=int(ceil(sqrt(len(images)))))
    return image.cpu().numpy().transpose(1, 2, 0)