-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathrun_model.py
54 lines (49 loc) · 2.52 KB
/
run_model.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
import os
import argparse
from libcity.pipeline import run_model
from libcity.utils import general_arguments, str2bool, str2float
def add_other_args(parser):
for arg in general_arguments:
if general_arguments[arg] == 'int':
parser.add_argument('--{}'.format(arg), type=int, default=None)
elif general_arguments[arg] == 'bool':
parser.add_argument('--{}'.format(arg),
type=str2bool, default=None)
elif general_arguments[arg] == 'str':
parser.add_argument('--{}'.format(arg),
type=str, default=None)
elif general_arguments[arg] == 'float':
parser.add_argument('--{}'.format(arg),
type=str2float, default=None)
elif general_arguments[arg] == 'list of int':
parser.add_argument('--{}'.format(arg), nargs='+',
type=int, default=None)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--task', type=str,
default='traffic_state_pred', help='the name of task')
parser.add_argument('--model', type=str,
default='GRU', help='the name of model')
parser.add_argument('--dataset', type=str,
default='METR_LA', help='the name of dataset')
parser.add_argument('--config_file', type=str,
default=None, help='the file name of config file')
parser.add_argument('--saved_model', type=str2bool,
default=True, help='whether save the trained model')
parser.add_argument('--train', type=str2bool, default=True,
help='whether re-train model if the model is \
trained before')
parser.add_argument("--local_rank", default=0, type=int)
parser.add_argument('--exp_id', type=str,
default=None, help='id of experiment')
add_other_args(parser)
args = parser.parse_args()
dict_args = vars(args)
other_args = {key: val for key, val in dict_args.items() if key not in [
'task', 'model', 'dataset', 'config_file', 'saved_model', 'train'] and
val is not None}
if args.gpu_id is not None:
os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(map(str, args.gpu_id))
run_model(task=args.task, model_name=args.model, dataset_name=args.dataset,
config_file=args.config_file, saved_model=args.saved_model,
train=args.train, other_args=other_args)