Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

35 lines (27 sloc) 977 Bytes
import pickle
import numpy as np
import tensorflow as tf
import dnnlib.tflib as tflib
import runway
fmt = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)
@runway.setup(options={'checkpoint': runway.file(extension='.pkl')})
def setup(opts):
global Gs
with open(opts['checkpoint'], 'rb') as file:
G, D, Gs = pickle.load(file)
return Gs
generate_inputs = {
'z': runway.vector(512, sampling_std=0.5),
'truncation': runway.number(min=0, max=1, default=0.8, step=0.01)
@runway.command('generate', inputs=generate_inputs, outputs={'image': runway.image})
def convert(model, inputs):
z = inputs['z']
truncation = inputs['truncation']
latents = z.reshape((1, 512))
images =, None, truncation_psi=truncation, randomize_noise=False, output_transform=fmt)
output = np.clip(images[0], 0, 255).astype(np.uint8)
return {'image': output}
if __name__ == '__main__':
You can’t perform that action at this time.