-
Notifications
You must be signed in to change notification settings - Fork 23
/
synthesize.py
84 lines (79 loc) · 3.62 KB
/
synthesize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import tensorflow as tf
import argparse
from src.synthesizer import Synthesizer
from src.synthesizer_styletransfer import SynthesizerStyleTransfer
from src.synthesizer_infinite import SynthesizerInfinite
from src.synthesizer_incremental import SynthesizerIncremental
from src.synthesizer_static import SynthesizerStatic
# set up argument parser
parser = argparse.ArgumentParser()
parser.add_argument('--batchsize', type=int, default=1,
help='input batch size')
parser.add_argument('--iter', type=int, default=6000,
help='number of iterations to optimize for')
parser.add_argument('--sfreq', type=int, default=1000,
help='number of iterations before saving a snapshot')
parser.add_argument('--noutfreq', type=int, default=100,
help='number of iterations before saving synthesized \
textures to disk')
parser.add_argument('--lfreq', type=int, default=100,
help='number of iterations before logging to disk')
parser.add_argument('--gpu', type=int, default=0, help='which GPU to use')
parser.add_argument('--runid', default='synthesized',
help='id assigned to this run')
parser.add_argument('--dynamics_target', default='',
help='path to target dynamic texture')
parser.add_argument('--appearance_target', default='',
help='path to target static texture')
parser.add_argument('--dynamics_model', default='MSOEnet',
help='path to dynamics modeling network')
parser.add_argument('--type', required=True, help='dts -> dynamic texture \
synthesis | dst -> dynamics style transfer | inf -> \
infinite/endless dynamic texture synthesis | inc -> \
incremental dynamic texture synthesis | sta -> static \
texture synthesis')
opt = parser.parse_args()
print(opt)
# config
config_proto = tf.ConfigProto()
config_proto.gpu_options.allow_growth = True
config_proto.allow_soft_placement = True
config_proto.log_device_placement = False
my_config = {}
my_config['batch_size'] = opt.batchsize
my_config['iterations'] = opt.iter
my_config['snapshot_frequency'] = opt.sfreq
my_config['network_out_frequency'] = opt.noutfreq
my_config['log_frequency'] = opt.lfreq
my_config['gpu'] = opt.gpu
my_config['run_id'] = opt.runid
my_config['dynamics_model'] = opt.dynamics_model
if opt.type == 'dts':
assert opt.dynamics_target != ''
s = Synthesizer(opt.dynamics_target,
config={'tf': config_proto,
'user': my_config})
elif opt.type == 'dst':
assert opt.appearance_target != ''
assert opt.dynamics_target != ''
s = SynthesizerStyleTransfer(opt.dynamics_target,
opt.appearance_target,
config={'tf': config_proto,
'user': my_config})
elif opt.type == 'inf':
assert opt.dynamics_target != ''
s = SynthesizerInfinite(opt.dynamics_target,
config={'tf': config_proto,
'user': my_config})
elif opt.type == 'inc':
assert opt.appearance_target != ''
assert opt.dynamics_target != ''
s = SynthesizerIncremental(opt.dynamics_target,
opt.appearance_target,
config={'tf': config_proto,
'user': my_config})
elif opt.type == 'sta':
s = SynthesizerStatic(opt.appearance_target,
config={'tf': config_proto,
'user': my_config})
s.optimize()