-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.py
70 lines (51 loc) · 1.8 KB
/
demo.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
import torch
import os
from torch.utils.data import DataLoader
from cmd_parser import parse_config
from modules import init, DatasetLoader, ModelLoader, LossLoader, seed_worker, set_seed
from utils.logger import savefig
###########global parameters#########
import sys
sys.argv = ['','--config=cfg_files\\demo.yaml']
def main(**args):
seed = 7
set_seed(seed)
# global setting
dtype = torch.float32
batchsize = args.get('batchsize')
num_epoch = args.get('epoch')
workers = args.get('worker')
device = torch.device(index=args.get('gpu_index'),type='cuda')
viz = args.get('viz')
mode = args.get('mode')
g = torch.Generator()
g.manual_seed(seed)
# init project setting
out_dir, logger, smpl = init(dtype=dtype, device=device, **args)
# load loss function
loss = LossLoader(device=device, **args)
# load model
model = ModelLoader(device=device, output=out_dir, smpl=smpl, **args)
# create data loader
dataset = DatasetLoader(smpl_model=smpl, dtype=dtype, **args)
test_dataset = dataset.load_testset()
test_loader = DataLoader(
test_dataset,
batch_size=batchsize, shuffle=False,
num_workers=workers, pin_memory=True,
worker_init_fn=seed_worker,
generator=g,
)
task = args.get('task')
exec('from process import %s_test' %task)
for epoch in range(num_epoch):
# testing mode
if epoch == 0 and mode == 'test':
training_loss = -1.
testing_loss = eval('%s_test' %task)(model, loss, test_loader, epoch, viz=viz, device=device)
lr = model.optimizer.state_dict()['param_groups'][0]['lr']
logger.append([int(epoch + 1), lr, training_loss, testing_loss])
logger.close()
if __name__ == "__main__":
args = parse_config()
main(**args)