Skip to content

Instantly share code, notes, and snippets.

@htoyryla
Last active February 27, 2018 04:43
Show Gist options
  • Save htoyryla/3e8b195ff63929db69ccc4e5287d8ae5 to your computer and use it in GitHub Desktop.
Save htoyryla/3e8b195ff63929db69ccc4e5287d8ae5 to your computer and use it in GitHub Desktop.
# git clone from https://github.com/tkarras/progressive_growing_of_gans
# download the snapshot from their Google drive
# use the following code in the same directory to generate random faces
import os
import sys
import time
import glob
import shutil
import operator
import theano
import lasagne
import dataset
import network
from theano import tensor as T
import config
import misc
import numpy as np
import scipy.ndimage
_, _, G = misc.load_pkl("network-snapshot-009041.pkl")
class Net: pass
net = Net()
net.G = G
import train
num_example_latents = 10
net.example_latents = train.random_latents(num_example_latents, net.G.input_shape)
net.example_labels = net.example_latents
net.latents_var = T.TensorType('float32', [False] * len(net.example_latents.shape))('latents_var')
net.labels_var = T.TensorType('float32', [False] * len(net.example_latents.shape)) ('labels_var')
net.images_expr = net.G.eval(net.latents_var, net.labels_var, ignore_unused_inputs=True)
net.images_expr = misc.adjust_dynamic_range(net.images_expr, [-1,1], [0,1])
train.imgapi_compile_gen_fn(net)
images = net.gen_fn(net.example_latents[:1], net.example_labels[:1])
misc.save_image(images[0], "fake2b.png", drange=[0,1])
@mtyka
Copy link

mtyka commented Oct 29, 2017

I think you want this ?
misc.save_image(images[0], "fake2b.png", drange=[0,1])
or better

for i in range(num_example_latents):
  misc.save_image(images[i], "fake2b.%05d.png"%i, drange=[0,1])

Thanks for posting, worked for me with their pre-trained models.

@htoyryla
Copy link
Author

@mtyka, thanks. Should have tested the file before posting but was in a hurry to get this is out.

@cohen5
Copy link

cohen5 commented Nov 2, 2017

Hi, I cannot find the file 'network-snapshot-009041.pkl' on the Google Drive (I have '009601' and four other files).
Does anyone now where I can find it?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment