Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
StyleGAN2: minimal usage
import pretrained_networks
import numpy as np
import dnnlib
import dnnlib.tflib as tflib
import PIL.Image
network_pkl = 'gdrive:networks/stylegan2-ffhq-config-f.pkl'
_, _, Gs = pretrained_networks.load_networks(network_pkl)
rng_seed = 5616
z = np.random.RandomState(rng_seed).randn(1, 512)
w = Gs.components.mapping.run(z, None) # [18, 512]
Gs_syn_kwargs = dnnlib.EasyDict()
Gs_syn_kwargs.output_transform = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)
Gs_syn_kwargs.randomize_noise = False
image = Gs.components.synthesis.run(w, **Gs_syn_kwargs)[0]
image = PIL.Image.fromarray(image)
image # display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment