Skip to content

Instantly share code, notes, and snippets.

@woctezuma
Created September 21, 2020 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woctezuma/71b89d6a61e373ddec08a5520e86055b to your computer and use it in GitHub Desktop.
Save woctezuma/71b89d6a61e373ddec08a5520e86055b to your computer and use it in GitHub Desktop.
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