-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrun.py
226 lines (194 loc) · 6.86 KB
/
run.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
from lib.config import cfg, args
def run_dataset():
from lib.datasets import make_data_loader
import tqdm
cfg.train.num_workers = 0
data_loader = make_data_loader(cfg, is_train=False)
for batch in tqdm.tqdm(data_loader):
pass
def run_network():
from lib.networks import make_network
from lib.datasets import make_data_loader
from lib.utils.net_utils import load_network
import tqdm
import torch
import time
network = make_network(cfg).cuda()
load_network(network, cfg.trained_model_dir, epoch=cfg.test.epoch)
network.eval()
data_loader = make_data_loader(cfg, is_train=False)
total_time = 0
for batch in tqdm.tqdm(data_loader):
for k in batch:
if k != 'meta':
batch[k] = batch[k].cuda()
with torch.no_grad():
torch.cuda.synchronize()
start = time.time()
network(batch)
torch.cuda.synchronize()
total_time += time.time() - start
print(total_time / len(data_loader))
def run_evaluate():
from lib.datasets import make_data_loader
from lib.evaluators import make_evaluator
import tqdm
import torch
from lib.networks import make_network
from lib.utils import net_utils
from lib.networks.renderer import make_renderer
cfg.perturb = 0
network = make_network(cfg).cuda()
net_utils.load_network(network,
cfg.trained_model_dir,
resume=cfg.resume,
epoch=cfg.test.epoch)
network.train()
data_loader = make_data_loader(cfg, is_train=False)
renderer = make_renderer(cfg, network)
evaluator = make_evaluator(cfg)
for batch in tqdm.tqdm(data_loader):
for k in batch:
if k != 'meta':
batch[k] = batch[k].cuda()
with torch.no_grad():
output = renderer.render(batch)
evaluator.evaluate(output, batch)
evaluator.summarize()
def run_relight_bkgd():
from lib.networks import make_network
from lib.datasets import make_data_loader
from lib.utils.net_utils import load_network
from lib.utils import net_utils
import tqdm
import torch
from lib.visualizers import make_visualizer
from lib.networks.renderer import make_renderer
cfg.perturb = 0
network = make_network(cfg).cuda()
network.eval()
load_network(network,
cfg.trained_model_dir,
resume=cfg.resume,
epoch=cfg.test.epoch)
data_loader = make_data_loader(cfg, is_train=False)
renderer = make_renderer(cfg, network)
visualizer = make_visualizer(cfg)
with torch.no_grad():
for batch in tqdm.tqdm(data_loader):
torch.cuda.empty_cache()
for k in batch:
if k != 'meta':
batch[k] = batch[k].cuda()
output = renderer.relight_npose_render(batch)
visualizer.visualize_relight_bkgd(output, batch)
del batch
del output
def run_relight_npose():
from lib.networks import make_network
from lib.datasets import make_data_loader
from lib.utils.net_utils import load_network
from lib.utils import net_utils
import tqdm
import torch
from lib.visualizers import make_visualizer
from lib.networks.renderer import make_renderer
cfg.perturb = 0
torch.set_num_threads(4)
network = make_network(cfg).cuda()
network.eval()
load_network(network,
cfg.trained_model_dir,
resume=cfg.resume,
epoch=cfg.test.epoch)
data_loader = make_data_loader(cfg, is_train=False)
renderer = make_renderer(cfg, network)
visualizer = make_visualizer(cfg)
with torch.no_grad():
for batch in tqdm.tqdm(data_loader):
torch.cuda.empty_cache()
for k in batch:
if k != 'meta':
batch[k] = batch[k].cuda()
output = renderer.relight_npose_render(batch)
visualizer.visualize_relight(output, batch)
del batch
del output
def run_relight():
from lib.networks import make_network
from lib.datasets import make_data_loader
from lib.utils.net_utils import load_network
from lib.utils import net_utils
import tqdm
import torch
from lib.visualizers import make_visualizer
from lib.networks.renderer import make_renderer
cfg.perturb = 0
network = make_network(cfg).cuda()
network.eval()
load_network(network,
cfg.trained_model_dir,
resume=cfg.resume,
epoch=cfg.test.epoch)
data_loader = make_data_loader(cfg, is_train=False)
renderer = make_renderer(cfg, network)
visualizer = make_visualizer(cfg)
with torch.no_grad():
for batch in tqdm.tqdm(data_loader):
torch.cuda.empty_cache()
for k in batch:
if k != 'meta':
batch[k] = batch[k].cuda()
output = renderer.relight_render(batch)
visualizer.visualize_relight(output, batch)
del batch
del output
def run_visualize():
from lib.networks import make_network
from lib.datasets import make_data_loader
from lib.utils.net_utils import load_network
from lib.utils import net_utils
import tqdm
import torch
from lib.visualizers import make_visualizer
from lib.networks.renderer import make_renderer
cfg.perturb = 0
network = make_network(cfg).cuda()
load_network(network,
cfg.trained_model_dir,
resume=cfg.resume,
epoch=cfg.test.epoch)
network.train()
data_loader = make_data_loader(cfg, is_train=False)
renderer = make_renderer(cfg, network)
visualizer = make_visualizer(cfg)
for batch in tqdm.tqdm(data_loader):
for k in batch:
if k != 'meta':
batch[k] = batch[k].cuda()
with torch.no_grad():
output = renderer.render(batch)
visualizer.visualize(output, batch)
def run_light_stage():
from lib.utils.light_stage import ply_to_occupancy
ply_to_occupancy.ply_to_occupancy()
# ply_to_occupancy.create_voxel_off()
def run_evaluate_nv():
from lib.datasets import make_data_loader
from lib.evaluators import make_evaluator
import tqdm
from lib.utils import net_utils
data_loader = make_data_loader(cfg, is_train=False)
evaluator = make_evaluator(cfg)
for batch in tqdm.tqdm(data_loader):
for k in batch:
if k != 'meta':
batch[k] = batch[k].cuda()
evaluator.evaluate(batch)
evaluator.summarize()
if __name__ == '__main__':
import os
import torch
torch.set_num_threads(4)
os.environ['CUDA_VISIBLE_DEVICES'] = ', '.join([str(gpu) for gpu in cfg.gpus])
globals()['run_' + args.type]()