-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_vae.py
54 lines (42 loc) · 1.33 KB
/
test_vae.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
from torch.nn.modules import linear
import visdom
from cfg import Opts
import mlutils
from mlutils import Log
from torch.utils.data import DataLoader
from trainer import get_trainer
from nature_datasets import get_data
from networks import get_vae
import time
def inference(opt, trainer):
_, eval_dataset = get_data(opt)
test_loader = DataLoader(eval_dataset,
batch_size=1,
shuffle=False,
num_workers=1,
pin_memory=True)
for item in test_loader:
Log.info('infer...')
image, _ = item
gen_image = trainer.infer_image(image)
time.sleep(1)
def main(opt):
saver = mlutils.Saver(opt)
saver.load_cfg(opt)
vae_cls = get_vae(opt)
vae = vae_cls(opt)
trainer_cls = get_trainer(opt)
trainer = trainer_cls(opt, vae)
trainer.load_state()
inference(opt, trainer)
if __name__ == '__main__':
Opts.add_int('device', 1, 'gpu id')
Opts.add_int('dashboard_port', 10010)
Opts.add_int('dashboard_server', False)
Opts.add_string('normalize', 'linear')
Opts.add_bool('test', True, 'on test stage')
Opts.add_string('model', 'latest', 'load latest/best model.')
Opts.add_string('id', '', required=True)
opt = Opts()
mlutils.init(opt)
main(opt)