Skip to content

Commit 358a046

Browse files
committed
Add initial RunwayML support from @genekogan's branch
2 parents d8933e8 + a3d2fb9 commit 358a046

6 files changed

Lines changed: 90 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* port of my encoder from @robertluxemburg
77
* fp16 branch from @veqtor
88
* tpu and swarm branches from @shawwn
9+
* runwayml support from @genekogan
10+
11+
<a href="https://open-app.runwayml.com/?model=pbaylies/stylegan2" target="_blank"><img src="https://open-app.runwayml.com/gh-badge.svg" /></a>
912

1013
**Various Improvements from skyflynil to make StyleGAN2 more suitible to be trained on Google Colab**
1114
* Supports Non-Square images, for example, 768x512, which basically as 6x4 (x2^7), or 640x384 as 5x3 (x2^7), etc.
@@ -95,6 +98,7 @@ This is an experimental port of [pbaylies/stylegan-encoder](https://github.com/p
9598
To test this, try out the notebook.
9699

97100
### Original Readme
101+
98102
![Teaser image](./docs/stylegan2-teaser-1024x256.png)
99103

100104
**Analyzing and Improving the Image Quality of StyleGAN**<br>

dnnlib/tflib/custom_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _run_cmd(cmd):
6161
raise RuntimeError('NVCC returned an error. See below for full command line and output log:\n\n%s\n\n%s' % (cmd, output))
6262

6363
def _prepare_nvcc_cli(opts):
64-
cmd = 'nvcc ' + opts.strip()
64+
cmd = 'nvcc --std=c++11 -DNDEBUG ' + opts.strip()
6565
cmd += ' --disable-warnings'
6666
cmd += ' --include-path "%s"' % tf.sysconfig.get_include()
6767
cmd += ' --include-path "%s"' % os.path.join(tf.sysconfig.get_include(), 'external', 'protobuf_archive', 'src')

requirements.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
absl-py==0.7.0
2+
astor==0.7.1
3+
certifi==2018.11.29
4+
chardet==3.0.4
5+
Click==7.0
6+
Flask==1.0.2
7+
Flask-Cors==3.0.7
8+
gast==0.2.2
9+
gevent==1.4.0
10+
greenlet==0.4.15
11+
grpcio==1.19.0
12+
h5py==2.9.0
13+
idna==2.8
14+
itsdangerous==1.1.0
15+
Jinja2==2.10
16+
Keras-Applications==1.0.7
17+
Keras-Preprocessing==1.0.9
18+
Markdown==3.0.1
19+
MarkupSafe==1.1.1
20+
mock==2.0.0
21+
numpy==1.16.2
22+
pbr==5.1.2
23+
Pillow==5.4.1
24+
protobuf==3.6.1
25+
requests==2.21.0
26+
six==1.12.0
27+
tensorflow-gpu==1.15.0
28+
termcolor==1.1.0
29+
urllib3==1.24.1
30+
Werkzeug==0.14.1
31+
wget==3.2
32+
runway-python

run_training.py

100755100644
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#----------------------------------------------------------------------------
3535

36-
def run(dataset, data_dir, result_dir, config_id, num_gpus, total_kimg, gamma, mirror_augment, mirror_augment_v, metrics, min_h, min_w, res_log2, lr, cond):
36+
def run(dataset, data_dir, result_dir, config_id, num_gpus, total_kimg, gamma, mirror_augment, mirror_augment_v, metrics, min_h, min_w, res_log2, lr, cond, resume_pkl, resume_kimg):
3737
train = EasyDict(run_func_name='training.training_loop.training_loop') # Options for training loop.
3838
G = EasyDict(func_name='training.networks_stylegan2.G_main') # Options for generator network.
3939
D = EasyDict(func_name='training.networks_stylegan2.D_stylegan2') # Options for discriminator network.
@@ -122,6 +122,7 @@ def run(dataset, data_dir, result_dir, config_id, num_gpus, total_kimg, gamma, m
122122
kwargs = EasyDict(train)
123123
kwargs.update(G_args=G, D_args=D, G_opt_args=G_opt, D_opt_args=D_opt, G_loss_args=G_loss, D_loss_args=D_loss)
124124
kwargs.update(dataset_args=dataset_args, sched_args=sched, grid_args=grid, metric_arg_list=metrics, tf_config=tf_config)
125+
kwargs.update(resume_pkl=resume_pkl, resume_kimg=resume_kimg)
125126
kwargs.submit_config = copy.deepcopy(sc)
126127
kwargs.submit_config.run_dir_root = result_dir
127128
kwargs.submit_config.run_desc = desc
@@ -182,6 +183,8 @@ def main():
182183
parser.add_argument('--res-log2', help='multiplier for image size, the training image size (height, width) should be (min_h * 2**res_log2, min_w * 2**res_log2)', default=4, type=int)
183184
parser.add_argument('--lr', help='base learning rate', default=0.003, type=float)
184185
parser.add_argument('--cond', help='conditional model', default=False, metavar='BOOL', type=_str_to_bool)
186+
parser.add_argument('--resume-pkl', help='pkl to resume training from: None)', default=None, type=str)
187+
parser.add_argument('--resume-kimg', help='kimg to resume training from" (default: 0)', default=0, type=int)
185188

186189
args = parser.parse_args()
187190

@@ -207,3 +210,4 @@ def main():
207210

208211
#----------------------------------------------------------------------------
209212

213+

runway.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
entrypoint: python runway_model.py
2+
python: 3.6
3+
cuda: 10.0
4+
spec:
5+
gpu: True
6+
cpu: False
7+
files:
8+
ignore:
9+
- checkpoints/*
10+
build_steps:
11+
- pip install -r requirements.txt

runway_model.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pickle
2+
import numpy as np
3+
import tensorflow as tf
4+
import dnnlib.tflib as tflib
5+
import runway
6+
7+
fmt = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)
8+
9+
@runway.setup(options={'checkpoint': runway.file(extension='.pkl')})
10+
def setup(opts):
11+
global Gs
12+
tflib.init_tf()
13+
with open(opts['checkpoint'], 'rb') as file:
14+
_G, _D, Gs = pickle.load(file, encoding='latin1')
15+
noise_vars = [var for name, var in Gs.components.synthesis.vars.items() if name.startswith('noise')]
16+
rnd = np.random.RandomState()
17+
tflib.set_vars({var: rnd.randn(*var.shape.as_list()) for var in noise_vars})
18+
return Gs
19+
20+
21+
generate_inputs = {
22+
'z': runway.vector(512, sampling_std=0.5),
23+
'truncation': runway.number(min=0, max=1, default=0.8, step=0.01)
24+
}
25+
26+
@runway.command('generate', inputs=generate_inputs, outputs={'image': runway.image})
27+
def convert(model, inputs):
28+
z = inputs['z']
29+
truncation = inputs['truncation']
30+
latents = z.reshape((1, 512))
31+
images = model.run(latents, None, truncation_psi=truncation, randomize_noise=False, output_transform=fmt)
32+
output = np.clip(images[0], 0, 255).astype(np.uint8)
33+
return {'image': output}
34+
35+
36+
if __name__ == '__main__':
37+
runway.run()

0 commit comments

Comments
 (0)