-
Notifications
You must be signed in to change notification settings - Fork 6
/
train_model_gait.py
182 lines (175 loc) · 4.29 KB
/
train_model_gait.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import argparse
import sys
import tensorflow as tf
from model.model_gait import ModelGait
from configuration import config
from util.utils import str2bool
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Arguments for train classification model")
parser.add_argument(
'-colab_path',
'--colab_path',
type=str,
default='',
help='colab path to data'
)
parser.add_argument(
'-summary_model',
'--summary_model',
type=str2bool,
default=False
)
parser.add_argument(
'-init_lr',
'--init_lr',
type=float,
default=0.001
)
parser.add_argument(
'-log_train',
'--log_train',
type=str2bool,
default=False
)
parser.add_argument(
'-stride',
'--stride',
default=1,
type=int
)
parser.add_argument(
'-fc',
'--fc',
type=str2bool,
default=False
)
parser.add_argument(
'-train',
'--train',
type=str2bool,
default=True
)
parser.add_argument(
'-epochs',
'--epochs',
default=100,
type=int
)
parser.add_argument(
'-filter_num_user',
'--filter_num_user',
default=None,
type=int
)
parser.add_argument(
'-model',
'--model',
type=str,
default='our',
choices=['our', 'paper']
)
parser.add_argument(
'-batch_size',
'--batch_size',
type=int,
default=128
)
parser.add_argument(
'-flatten',
'--flatten',
default=False,
type=str2bool
)
parser.add_argument(
'-method',
'--method',
type=str,
default='cycle_based',
choices=['cycle_based', 'window_based', 'window_based_svm']
)
parser.add_argument(
'-window_len',
'--window_len',
type=int
)
parser.add_argument(
'-overlap',
'--overlap',
type=int
)
parser.add_argument(
'-split',
'--split',
type=str,
choices=['standard', 'paper']
)
parser.add_argument(
'-denoise',
'--denoise',
type=str2bool
)
parser.add_argument(
'-autocorr',
'--autocorr',
type=str2bool,
default=False
)
parser.add_argument(
'-augment_data',
'--augment_data',
type=str2bool,
default=False
)
parser.add_argument(
'-plot_split',
'--plot_split',
type=str2bool,
default=False
)
parser.add_argument(
'-gyroscope',
'--gyroscope',
type=str2bool,
default=False
)
parser.add_argument(
'-train_svm',
'--train_svm',
type=str2bool,
default=False
)
parser.add_argument(
'-only_magnitude',
'--only_magnitude',
type=str2bool,
default=False
)
parser.add_argument(
'-methods_aug',
'--methods_aug',
type=str,
help='methods to apply in data augmentation',
required=False)
args = parser.parse_args()
# GPU settings
gpus = tf.config.list_physical_devices("GPU")
if gpus:
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
model = ModelGait(config, args.colab_path)
model.load_data(filter_num_user=args.filter_num_user,method=args.method, window_len=args.window_len, overlap=args.overlap, denoise=args.denoise, autocorr=args.autocorr, gyroscope=args.gyroscope)
model.split_train_test(method=args.method, split=args.split, plot_split=args.plot_split)
if args.train_svm:
model.train_svm(only_magnitude=args.only_magnitude)
else:
if args.augment_data:
model.augment_train_data(methods=args.methods_aug)
model.normalize_data()
model.create_tf_dataset(batch_size=args.batch_size)
model.build_model(stride=args.stride, fc=args.fc, flatten=args.flatten,
summary=args.summary_model, name=args.model)
if args.train:
model.loss_metric(init_lr=args.init_lr)
model.train_model(log=args.log_train, epochs=args.epochs)
model.test_model()