Skip to content

Commit 3c97be0

Browse files
committed
har_trees: Support multiple datasets on device
1 parent 7dc0f76 commit 3c97be0

File tree

3 files changed

+23
-75
lines changed

3 files changed

+23
-75
lines changed

examples/har_trees/har_live.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,24 @@ def mean(arr):
1616

1717
def main():
1818

19-
classname_index = {"LAYING": 0, "SITTING": 1, "STANDING": 2, "WALKING": 3, "WALKING_DOWNSTAIRS": 4, "WALKING_UPSTAIRS": 5}
19+
dataset = 'har_exercise_1'
20+
21+
if dataset == 'uci_har':
22+
classname_index = {"LAYING": 0, "SITTING": 1, "STANDING": 2, "WALKING": 3, "WALKING_DOWNSTAIRS": 4, "WALKING_UPSTAIRS": 5}
23+
window_length = 128
24+
elif dataset == 'har_exercise_1':
25+
classname_index = {"jumpingjack": 0, "lunge": 1, "other": 2, "squat": 3}
26+
window_length = 256
27+
else:
28+
raise ValueError('Unknown dataset')
29+
30+
model_path = f'{dataset}_trees.csv'
2031
class_index_to_name = { v: k for k, v in classname_index.items() }
2132

33+
2234
# Load a CSV file with the model
2335
model = emlearn_trees.new(10, 1000, 10)
24-
with open('har_uci_trees.csv', 'r') as f:
36+
with open(model_path, 'r') as f:
2537
emlearn_trees.load_model(model, f)
2638

2739
mpu = MPU6886(I2C(0, sda=21, scl=22, freq=100000))
@@ -30,8 +42,7 @@ def main():
3042
mpu.fifo_enable(True)
3143
mpu.set_odr(100)
3244

33-
window_length = 100
34-
hop_length = 50
45+
hop_length = 64
3546
chunk = bytearray(mpu.bytes_per_sample*hop_length)
3647

3748
x_values = empty_array('h', hop_length)

examples/har_trees/har_run.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,20 @@ def main():
5353

5454
model = emlearn_trees.new(10, 1000, 10)
5555

56+
dataset = 'har_uci'
57+
dataset = 'har_exercise_1'
58+
59+
model_path = f'{dataset}_trees.csv'
60+
5661
# Load a CSV file with the model
57-
with open('har_uci_trees.csv', 'r') as f:
62+
with open(model_path, 'r') as f:
5863
emlearn_trees.load_model(model, f)
5964

6065

6166
errors = 0
6267
total = 0
63-
data_path = 'har_uci.testdata.npz'
68+
data_path = f'{dataset}.testdata.npz'
69+
print('har-run-load', data_path)
6470
for features, labels in har_load_test_data(data_path):
6571

6672
assert len(labels) == 1

examples/har_trees/har_screen.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)