nnabla-examples icon indicating copy to clipboard operation
nnabla-examples copied to clipboard

Query: StyleGAN2 latent_seed

Open KomputerMaster64 opened this issue 2 years ago • 3 comments

Respected sir Thank you for sharing the projects and the pre-trained models. I have been trying to use the StyleGAN2 notebook. I want to generate multiple random samples, but the latent_seed command is limiting the results. I wanted to ask how to generate a grid of random results.

I am sharing the link to the cell I want to refer to here.

KomputerMaster64 avatar Sep 02 '22 19:09 KomputerMaster64

Thanks for using our Colab demo.

Unfortunately the link is not working properly, so we don't know which cell you mention, but if you mention the cell for simple image generation (the cell after Now let's run StyleGAN2! ), you cannot make a grid image as is. You need to edit the cell. Can you tell us what kind of grid images you want? We can let you know how to then.

Or, the cell for style mixing, you can make grid image by, for example, specifying batch_size_A = 3 and batch_size_B = 3 in the configuration cell. The resulting image should be like the following.

image

TakuyaYashima avatar Sep 06 '22 04:09 TakuyaYashima

Thank you for the response. I wanted to know if I have saved some images in a directory using the model, how can I make the grid of N*M dimensions from them for analysing the results.

KomputerMaster64 avatar Sep 09 '22 08:09 KomputerMaster64

Sorry for the late reply! You might have already found the solution, but hope this can help (very primitive way though). Should work on Colab (or they provide some convenient ways!)

import numpy as np
from nnabla.utils.image_utils import imread, imsave

filepaths = [
             [filepath00, filepath01, filepath02, ...],
             [filepath10, filepath11, filepath12, ...],
             [filepath20, filepath21, filepath22, ...],
             ]  # specify image paths
assert len(set([len(_) for _ in filepaths])) == 1
imgs = list()

for row in range(filepaths):
    imgs.append(np.concatenate([imread(_, size=(256, 256)) for _ in row], axis=1))
    # axis=0 is vertical, axis=1 is horizontal
grid_imgs = np.concatenate([img for img in imgs], axis=0)

imsave(savepath, grid_imgs)  # specify saving image paths

TakuyaYashima avatar Sep 27 '22 06:09 TakuyaYashima