Skip to content

Commit 7968495

Browse files
committed
har_trees: Add support for exercise dataset
1 parent c192162 commit 7968495

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

examples/har_trees/compute_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def compute_dataset_features(data: npyfile.Reader,
1515
assert len(shape) == 3, shape
1616
n_samples, window_length, n_axes = shape
1717
assert n_axes == 3, shape
18-
assert window_length == 128, shape
18+
#assert window_length == 128, shape
1919

2020
# We expect data to be h/int16
2121
assert data.typecode == DATA_TYPECODE, data.typecode

examples/har_trees/har_train.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def export_model(path, out):
222222
def run_pipeline(run, hyperparameters, dataset,
223223
data_dir,
224224
out_dir,
225+
model_settings=dict(),
225226
n_splits=5,
226227
features='timebased',
227228
):
@@ -252,6 +253,14 @@ def run_pipeline(run, hyperparameters, dataset,
252253
'running', 'rope_jumping',
253254
],
254255
),
256+
'har_exercise_1': dict(
257+
groups=['file'],
258+
data_columns = ['x', 'y', 'z'],
259+
classes = [
260+
#'mixed',
261+
'squat', 'jumpingjack', 'lunge', 'other',
262+
],
263+
),
255264
}
256265

257266
if not os.path.exists(out_dir):
@@ -272,8 +281,16 @@ def run_pipeline(run, hyperparameters, dataset,
272281
data_load_duration = time.time() - data_load_start
273282
log.info('data-loaded', dataset=dataset, samples=len(data), duration=data_load_duration)
274283

284+
285+
275286
feature_extraction_start = time.time()
276-
features = extract_features(data, columns=data_columns, groupby=groups, features=features)
287+
features = extract_features(data,
288+
columns=data_columns,
289+
groupby=groups,
290+
features=features,
291+
window_length=model_settings['window_length'],
292+
window_hop=model_settings['window_hop'],
293+
)
277294
labeled = numpy.count_nonzero(features['activity'].notna())
278295

279296
feature_extraction_duration = time.time() - feature_extraction_start
@@ -293,9 +310,10 @@ def run_pipeline(run, hyperparameters, dataset,
293310
print('Class distribution\n', features['activity'].value_counts(dropna=False))
294311

295312
# Run train-evaluate
313+
evaluate_groupby = groups[0]
296314
results, estimator = evaluate(features,
297315
hyperparameters=hyperparameters,
298-
groupby='subject',
316+
groupby=evaluate_groupby,
299317
n_splits=n_splits,
300318
)
301319

@@ -362,6 +380,10 @@ def parse():
362380

363381
parser.add_argument('--features', type=str, default='timebased',
364382
help='Which feature-set to use')
383+
parser.add_argument('--window-length', type=int, default=128,
384+
help='Length of each window to classify (in samples)')
385+
parser.add_argument('--window-hop', type=int, default=64,
386+
help='How far to hop for next window to classify (in samples)')
365387

366388
args = parser.parse_args()
367389

@@ -391,6 +413,10 @@ def main():
391413
data_dir=args.data_dir,
392414
run=run_id,
393415
hyperparameters=hyperparameters,
416+
model_settings=dict(
417+
window_hop=args.window_hop,
418+
window_length=args.window_length,
419+
),
394420
n_splits=int(os.environ.get('FOLDS', '5')),
395421
features=args.features,
396422
)

0 commit comments

Comments
 (0)