1)Establishing the baseline for the project from the TinyML book
We first used the instructions from Pete Warden’s TinyML book as a starting point. We ran into issues uploading the code onto our Arduino Nano 33 BLE Sense board. The board would disconnect as soon as the code was uploaded. We realized the issue was a result of using the most recent version of the Arduino code, so we reverted to the version referenced in the book. Once we confirmed the code could be uploaded, we went in and patched the Arduino_LSM9DS1/src/LSM9DS1.cpp file (see picture) as directed in the book and then uploaded the code to the board.
2)Creating code to collect data from the accelerometer
Once we confirmed that the code was able to recognize all 3 gestures, we began collecting our own dataset for the 3 gestures. To do this, we used a “Accelerometer_DataCollection.ino” Arduino file that we created to collect and display the data in the correct format to replace the data previously used to train the model. To create this code, we referenced two external examples: Dale Giancono’s Nano33BLESensorExample_accelerometer.ino example, and code from Daniel Hertz on MakerPro. Both sources are referenced in our “Work Attribution” page.
3)Collecting our data
We each performed the gestures 10 different times while using the program located in the “Code” section to record the data from the accelerometer for a total of 30 data sets per gesture. We saved each data set as a plain text file.
4) Training a model from our dataTo train the model, we used the code located at https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/magic_wand/train/train_magic_wand_model.ipynb. We created a copy of the Jupyter notebook and uploaded our data sets into the generated train directory alongside the pre-existing data. Then, we modified the names array in data_prepare.py to include the names on our plain text data files, and modified data_split_person.py so that one team member’s data each was used for training, verification, and testing. After running the notebook, we downloaded the generated model.cc file containing the new model. Our copy of the notebook is viewable at https://deepnote.com/project/a748e8ab-8c0c-4692-bf9c-dec9a33f7cd9.
5) Inputting the trained model into the existing frameworkNext we opened up the C++ file, which contained two variables: the unsigned character array model_tflite[] and the unsigned integer model_tflite_len. We pasted their values into the magic_wand_model_data.cpp file, replacing the values of the constant unsigned character array DATA_ALIGN_ATTRIBUTE[] and the constant integer g_magic_wand_model_data_len respectively. The code uploaded successfully, but was giving the error “Didn’t find op for builtin opcode ‘RESHAPE’ version 1”. This was because the reshape opcode was not defined in the setup, so we had to add the following line to the Arduino file (magic_wand.ino):
86 micro_mutable_op_resolver.AddBuiltin(tflite::BuiltinOperator_RESHAPE, tflite::ops::micro::Register_RESHAPE());
After adding the new line, we uploaded the code to our board and the application worked properly.
Demo
Comments
Please log in or sign up to comment.