Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
113 lines (96 loc) · 3.17 KB
/
Copy pathmain.py
File metadata and controls
113 lines (96 loc) · 3.17 KB
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
# encoding: utf-8
"""
This function denotes the main function to train/test/plot
Usage:
python main.py [FLAGS]
@author: gongzhiqiang
@contact: gongzhiqiang@alumni.sjtu.edu.cn
@version: 1.0
@file: main.py
@time: 2021-06-29
"""
from pathlib import Path
import configargparse
from src.DeepRegression import Model
from src import train, test, plot, point
def main():
# default configuration file
config_path = Path(__file__).absolute().parent / "config/config.yml"
data_path = Path(__file__).absolute().parent / "config/data.yml"
parser = configargparse.ArgParser(
config_file_parser_class=configargparse.YAMLConfigFileParser,
default_config_files=[str(config_path), str(data_path)],
description="Hyper-parameters.",
)
# configuration file
parser.add_argument(
"--config", is_config_file=True, default=False, help="config file path"
)
# mode
parser.add_argument(
"-m", "--mode", type=str, default="train", help="model: train or test or plot"
)
# problem dimension
parser.add_argument(
"--prob_dim", default=2, type=int, help="dimension of the problem"
)
# args for plot in point-based methods
parser.add_argument("--plot", action="store_true", help="use profiler")
# args for training
parser.add_argument(
"--gpu",
type=int,
default=0,
help="which gpu: 0 for cpu, 1 for gpu 0, 2 for gpu 1, ...",
)
parser.add_argument("--batch_size", default=16, type=int)
parser.add_argument("--max_epochs", default=20, type=int)
parser.add_argument("--lr", default="0.01", type=float)
parser.add_argument(
"--resume_from_checkpoint", type=str, help="resume from checkpoint"
)
parser.add_argument(
"--num_workers", default=2, type=int, help="num_workers in DataLoader"
)
parser.add_argument("--seed", type=int, default=1, help="seed")
parser.add_argument(
"--use_16bit", type=bool, default=False, help="use 16bit precision"
)
parser.add_argument("--profiler", action="store_true", help="use profiler")
# args for validation
parser.add_argument(
"--val_check_interval",
type=float,
default=1,
help="how often within one training epoch to check the validation set",
)
# args for testing
parser.add_argument(
"-v", "--test_check_num", default="0", type=str, help="checkpoint for test"
)
parser.add_argument("--test_args", action="store_true", help="print args")
# args from Model
parser = Model.add_model_specific_args(parser)
hparams = parser.parse_args()
PointModel = [
"RSVR",
"RBM",
"RandomForest",
"Polynomial",
"MLPP",
"Kriging",
"KInterpolation",
"GInterpolation",
]
dpoint = True if hparams.model_name in PointModel else False
# running
assert hparams.mode in ["train", "test", "plot"]
if hparams.test_args:
print(hparams)
elif dpoint:
print(f"Only testing is permitted for", hparams.model_name)
point.main(hparams)
else:
getattr(eval(hparams.mode), "main")(hparams)
if __name__ == "__main__":
main()