forked from SeuTao/FaceBagNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (52 loc) · 2.38 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys
sys.path.append("..")
import argparse
from test import run_test
from train import run_train
from realtime import run_realtime
# run train or dest function, dependant on input arguments
def main(cfg):
# TODO: implement device selection
# if config.device == "auto":
# device =
# elif config.device == "cpu":
# net = net.cpu()
# elif config.device == "gpu":
# net = net.cuda()
# else:q
# raise ValueError
if cfg.mode.startswith("train"):
run_train(cfg)
elif cfg.mode.startswith("test"):
# take the best model on validation set
cfg.pretrained_model = r'global_min_acer_model.pth'
run_test(cfg, dir='global_test_36_TTA')
elif cfg.mode == 'realtime':
cfg.pretrained_model = r'global_min_acer_model.pth'
run_realtime(cfg)
return
# parse input arguments and pass them to main function
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--train_fold_index', type=int, default = -1)
parser.add_argument('--model', type=str, default='model_A')
parser.add_argument('--image_mode', type=str, default='color', choices=['color', 'depth', 'ir'])
parser.add_argument('--image_size', type=int, default=48) # empirically adjusted
parser.add_argument('--train_batch_size', type=int, default=128)
parser.add_argument('--valid_batch_size', type=int, default=128)
parser.add_argument('--test_batch_size', type=int, default=20)
parser.add_argument('--num_restarts', type=int, default=50) # number of random restarts
parser.add_argument('--epochs', type=int, default=50)
parser.add_argument('--epochs_valid_start', type=int, default=50)
parser.add_argument('--mode', type=str, default='train',
choices=['train', 'infer_test', 'test', 'test-single', 'realtime'])
parser.add_argument('--stream', default=None)
parser.add_argument('--pretrained_model', type=str, default=None)
parser.add_argument('--dataset_workers', type=int, default=4)
parser.add_argument('--device', type=str, choices=["auto", "gpu", "cpu"], default="auto")
parser.add_argument('--train_list', type=str, default=None)
parser.add_argument('--validation_list', type=str, default=None)
parser.add_argument('--test_list', type=str, default=None)
config = parser.parse_args()
main(config)
print("end")