@@ -11,7 +11,7 @@ The same kind of approach can also be applied to animals (*Animal Activity Recog
11
11
which enables tracking of pets, lifestock and wild animals.
12
12
This has been used for many kinds of animals - such as cats, dogs, diary cattle.
13
13
14
- The same approach can be used for simple gesture recognition.
14
+ The same approach can be used for simple gesture recognition, at least for repetitive gestures .
15
15
16
16
## Status
17
17
Working. Tested running on ESP32 with MicroPython 1.24.
@@ -22,6 +22,9 @@ The dataset used is rather simple, and may not reflect the data you get from you
22
22
- which will lead to poor classifications.
23
23
For a real world usage you should probably replace the dataset with your own data, collected on your own device.
24
24
25
+ At the bottom on the README there are some instructions and tools for collecting your own data,
26
+ and training a custom model on such a dataset.
27
+
25
28
## Machine Learning pipeline
26
29
27
30
This example uses an approach based on the paper
@@ -118,8 +121,8 @@ mpremote har_live.py
118
121
119
122
## Run training
120
123
121
- This will train a new model.
122
- Uses CPython on the PC.
124
+ This will train a new model for the HAR UCI dataset .
125
+ You need to have Python ( CPython) installed on the PC.
123
126
124
127
Install requirements
125
128
```
@@ -139,4 +142,85 @@ python har_train.py
139
142
This will output a new model (named ` _trees.csv ` ).
140
143
Can then be deployed to device following the steps above.
141
144
145
+ ## Recording motion data for custom tasks
146
+
147
+ To learn a classifier for your own custom tasks, you will need to: 1) record data, 2) label the data, 3) run training with custom data.
148
+ This example provides some basic tools to assist with this process.
149
+
150
+ Recording data. Requires a M5StickC PLUS 2.
151
+ Before you do this, make sure to ** first run live classification example** (to get the dependencies).
152
+
153
+ ```
154
+ mpremote run har_record.py
155
+ ```
156
+
157
+ Alternatively: Copy the program to device.
158
+ This way it will run even if there is no USB device connected.
159
+ ```
160
+ mpremote cp har_record.py main.py
161
+ mpremote reset
162
+ ```
163
+
164
+ To get good timestamps on the recorded files, rembember to set the RTC clock.
165
+ ```
166
+ mpremote rtc --set
167
+ ```
168
+
169
+ When the recording program runs, the device should show a screen which allows to select between different classes.
170
+ Clicking the big button by the screen allows selecting class.
171
+ Holding the big button down allows to start recording.
172
+ The red LED will light up while recording.
173
+
174
+ This allows to coarsely label the classes, which is helpful to sort and annotate them later.
175
+ To adjust the classes, make changes to ` har_record.py ` .
176
+
177
+ The files are placed in the ` data/ ` folder on the internal FLASH filesystem.
178
+
179
+ To copy the files over to your computer, for building a dataset, use
180
+ ```
181
+ mkdir ./data/raw/mydata1/
182
+ mpremote cp -r :./har_record ./data/raw/mydata1/
183
+ ```
184
+
185
+ ## Labeling recorded motion data
186
+
187
+ To label the motion data, we can use [ Label Studio] ( https://labelstud.io/ ) .
188
+ You can use their hosted version, or run it in Docker, or install it via ` pip ` .
189
+
190
+ There is a ready-made Label Studio task defintion provided,
191
+ in the file ` labeling/har_classify_config.xml ` .
192
+
193
+ There is a tool designed to convert the .npy files from the ` har_record.py ` application
194
+ into .csv files understood by Label Studio.
195
+
196
+ ```
197
+ python har_data2labelstudio.py
198
+ ```
199
+
200
+ When you have started Label Studio, create a new Project, and Import the .CSV files as data.
201
+ Then you can label each piece of data.
202
+
203
+
204
+ Then use this tool to combine the sensor data files with the labels.
205
+ ```
206
+ python har_labelstudio2dataset.py
207
+ ```
208
+
209
+ This will produce a dataset as a .parquet file, which can be used with ` har_train.py ` .
210
+
211
+
212
+ ## Train model on custom dataset
213
+
214
+
215
+ Add your dataset definition to ` dataset_config ` in ` har_train.py ` , with a unique name (example ` mydata1 ` ).
216
+
217
+ Then you can run the training process.
218
+
219
+ ```
220
+ python har_train.py --dataset mydata1
221
+ ```
222
+
223
+ It should output a new model (named ` _trees.csv ` ).
224
+ This model can be deployed to device following the steps above.
225
+
142
226
0 commit comments