The Unity project has a lot of room for expansion. One area is to fix the machine learning implemtation
on the unity side. There is a bug in the MainPredict.cs script that causes it to generete enormous arrays
and eventually crash the webGL canvas. The other area is to improve and expand the game aspect (ie physics, camera controls, levels etc...).
Overview
The machine learning side of this project has many aspects and parameters that can be modified. We will go over each file to dive into what variables can be changed, what variables need to be changed, and how that will affect the running of the code and training/prediction of the model.
Main_CollectData.py
The first variable that should be changed for every data collection session is “SAVE_FILE”. If this value is not changed at the beginning of a new training session to something unique, the old data will be overwritten.
The next four variables worth mentioning are “RECORD_DURATION”, “NUM_TRIALS”, “NUM_PEOPLE”, and “ACTIVE_CHANNELS”. “RECORD_DURATION” is how long a gesture will be recorded for. We stuck with 5 seconds over the course of the project. “NUM_TRIALS” determines the number of trials for each gesture being recorded. We increased this number to 15 for our largest data collection, but used as low as 5 when testing preliminary models. “NUM_PEOPLE” is the number of people from whom the data will be collected. This value remained 1 for most of the project, but was increased to 5 when we wanted to collect data for our whole group. After one person records all their gestures, the program pauses and waits until “ENTER” is pressed to record for the next person. “ACTIVE_CHANNELS” is the EMG channels recorded. As we only used one for the duration of our project, this was only channel 0. However, this could be expanded to use all 4 of the EMG channels if needed.
The “GESTURES” variable is a Python dictionary that assigns a numerical value to each gesture that will be recorded over the course of the data collection. This variable will need to be changed if gesture classification is expanded further than just fist squeeze and rest.
Main_Train.py
The first relevant variable in the training file is the dataframe variable, “df”. This variable must be correctly edited to load a dataframe of the correct .csv file that was just saved in the data collection step.
The next two variables are “window_size” and “overlap”. Window size refers to the number of samples that will be used to make a classification decision in the CNN. We found that increasing this variable increased accuracy but decreased responsiveness, meaning that transitions between states were a little slow. The “overlap” is the percent of the window size that will be shifted to analyze the next window. With our window size being 100 and the overlap being 0.25, the first signals 0-99 will be analyzed, then 25-124, 50-149, and so on. This remained at 0.25 over the course of the project.
Our neural network is defined in the build_cnn_model method. The neural network we defined and used was a fairly simple neural network, using only a few layers and classifying into 2 outputs. The neural network is adequate for a small number of outputs, but should be expanded if a more diverse gesture classification is pursued later.
Towards the end of the file, 3 files are saved. Similar to previous file names, these must also be changed after each run through the pipeline. We typically kept the suffix the same for all of our files for simplicity.
Main_Prediction.py
At the beginning of the prediction file, the 3 files saved at the end of the training are immediately loaded. Once again, make sure these file names align with what was just saved in the training portion of the pipeline.
Similar to the data collection file, “ACTIVE_CHANNELS” and “GESTURES” are defined. Same as before, make sure only the EMG channels that data was collected from and the model was trained on are used. “GESTURES” will need to be changed if more gestures are added later.