-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (40 loc) · 1.52 KB
/
main.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
import torch
from torch.utils.data import DataLoader
from dataset.ubfc_rppg import UbfcDataset, UbfcDataLoader
from dataset.pure import PureDataset, PureDataLoader
from configs.config import TrainArgs, UBFCArgs, PureArgs
from model.trainer import Trainer
from utils import set_random_seed
if __name__ == '__main__':
try:
# 42 is the magic number
SEED = 42
set_random_seed(SEED)
train_args = TrainArgs()
trainer = Trainer(train_args)
logger = trainer.logger
logger.info(f"SEED: {SEED}")
# get dataloader
ubfc_rppg_args = UBFCArgs()
pure_args = PureArgs()
# train_loader, test_loader = UbfcDataLoader(ubfc_rppg_args, train_args).get_dataloder()
train_loader, test_loader = PureDataLoader(pure_args, train_args).get_dataloder()
# run
if train_args.mode == 'train_test':
trainer.train(train_loader)
if test_loader is not None:
trainer.test(test_loader)
else:
logger.info('Test_loader is None, use train_loader for test.')
trainer.test(train_loader)
elif train_args.mode == 'only_test':
if test_loader is not None:
trainer.test(test_loader)
else:
trainer.test(train_loader)
else:
logger.error(f"unsupported mode: {train_args.mode}")
raise
except Exception as e:
logger.error(f"error: {str(e)}")
raise