Mind Patterning – Phase 1

What and Why

I’ve always been fascinating by the idea of moving ones mind to a robot to live forever as a machine so I thought what better time to start the seeds of this with a nice bit of Raspberry Pi work with TensorFlow and a Muse brainwave reading Headset – starting off simple and working my way up:

71sOGEEFn1L._AC_SX466_

Key Goals:

  1. Read brainwave data.
  2. Use TensorFlow to train a model on brainwave data to determine a relaxed or a non-relaxed mindset.
  3. Use information gathered from this as a jumping off point to see what else can be read from the mind.

I decided on the name Mind Patterning as in the video game Total Annihilation (the thumbnail for this post is artwork from the game) the story goes that humanity found a way to transfer human minds into robots and the process is called patterning. I am also inspired by Dr Samuel Hayden from DOOM 2016 – who transferred his mind into a super combat chassis.

Image result for dr samuel hayden
Mind Patterning – Phase 10.

Stuff:

How

First I needed a way to get mind data after some Googling I found a head band exists called the Muse – this can read EEG data from the wearers mind and be used with an app to determine how relaxed someone is during meditation sessions.

With some further reading I realised it could be hooked up to a Raspberry Pi with Bluetooth rather easily and that it could then spit out the raw sensor data into a CSV file. Looking into the code here I discovered that there is code to turn the raw sensor data into more usable brainwave data and then write that to a CSV.

There was some extra stuff I needed to do before the headset would work, I noted the sites I used for instructions:

I then went to here to learn about loading CSV data into a TensorFlow model and training on it.

You can find out about installing TensorFlow on a Pi here.

The initial testing of the model training and inference was done with the PipelineRunnerTest.py file which will run through and create an artificial set of training data and then again for testing data, it then calls the CSV pre-processing which then loads and trains the model, then it runs that against the test data.

This allowed me to see easily and quickly how well the model would even work against similar numbers to what the real world data was. It’s also very useful for quickly making adjustments to the training in terms of epochs/batch sizes and what optimiser to use etc.

The CSV data looks like this (example of artificially generated data):

csvExample

In the end I stuck with very similar settings to what the CSV loading tutorial taught me as that seemed to work pretty well but I will be experimenting to see if it can be made more efficient, by adding layers etc.

The actual data I will be gathering and using will be Alpha, Beta and Theta waves calculated from the raw data from the EEG sensors on the headband.

For more information about these waves have a look here, as a high level summary – essentially the differing of measurements from these 3 waves are the result of the mind being in certain states; for instance a certain wave being higher and another being lower means a relaxed state of mind and vice versa. So this data can be used to detect the state of mind and train the model I want to make in TensorFlow.

At this point I’ll mention my third inspiration for this project – Ira Graves from the Star Trek TNG episode ‘The Schizoid Man‘, where he transfers his mind into Lt. Data to avoid death.

You can get the code from my GitHub.

So lets walk through the modules of code (using Python 3):

TestDataGeneratorCSVbatch:

Generates an artificial data set, can be used to determine the number of lines written, the type of data being written and also the output file name of the data.

This is modified from the code here.

CSVCombiner:

Takes a number of files with certain filename templates (such as beginning with ‘input_test_data_’) and combines them into a single CSV with a set name. This is where the multiple instances of gathering data are put together into a single CSV for the CSVDataImporter. Thanks to the code from here.

CSVDataImporter:

This is where the CSV data is imported and numerically packed into variables that TensorFlow can handle in the below module. This is code from here.

BrainWaveTrainer:

Takes data from the data importer and trains a model on it and then outputs that model to data inference below. This is code from here.

BrainWaveDataInference:

This runs the test data against the model that was built above and then displays the results (a sample of 50). This is code from here.

RealDataGatherer.py

This gathers relax data and then non-relaxed data from the EEG headband, instructing the user wearing it to relax/non-relax their mind. Then calls the RealBrainWaveData module which gathers the data and writes to separate CSV files for each run, then finally calling the combiner module to put them into one big CSV.

It’s done in a way that per-call it will request for a batch of relaxed mind data (user relaxes, clears mind) then asks for non-relaxed (user does best to think and fill mind with as many thoughts and be as non-relaxed as possible).

I did this in a way that gathers smaller batches of mind data and then combines them int a bigger set, this is because sustaining a relaxed mind for long is difficult for me, so it’s easy to batch it up with small samples of when I get my brain to just be quiet.

RealBrainWaveDataCSV.py

This is the module that grabs the data from the EEG module and puts it into CSV files, calling the stream module as a seperate thread (because if the muselsl stream is called it takes over the console and the code won’t move forward until the stream has finished). Then it takes in a number of seconds of data, that can be passed in – then calculates the sensor data into Alpha/Beta/Theta waves that get written to a CSV.

This first recorded 30 seconds of EEG data at a time, then after some testing it was raised to 2 minutes – although I will probably make this configurable at some point.

This is modified from the code here.

MuseStreamBegin.py

This code is from here it basically just starts a connection with the Muse headset and begins a data stream.

PipelineRunnerTest.py

This runs the full pipeline to test the training and inference using artificial data:

  1. Generates CSV data – train/test
  2. Imports and Pre-processes data
  3. Trains model on data
  4. Inferences and shows results

PipelineRunnerReal.py

This runs the full pipeline but with real data instead of artificial data:

  1. Gathers CSV data from headset – train/test
  2. Imports and pre-processes data
  3. Trains model on data
  4. Inferences and shows results

Both pipelines use a batch size of 250, epochs 10 and the test runner creates a total CSV size of around 688,891 rows for train and 68,281 for test by default, but these can be adjusted with args passed into the pipeline (-h at the end of the files to get the info on args, for example; ‘python3 PipelineRunnerTest.py -h’).

colors.py

This is used to color the print output when running a pipeline.

This is from here.

utils.py

This is some extra gear that game down with the muse-lsl stuff from above.

 

Each of these can be called independently also to test their individual features, much like a unit test.

The pipeline runners are the main ones though, allowing me to test the entire pipeline with artificial data and then also with real data. Let’s see what the results are like…

Testing & Results

12
Here we go.

PipelineRunnerTest

With the current configuration of train size, batch size and epochs I managed to get consistently around these results with the artificial data:

Test Loss 0.27878854962912475, Test Accuracy 0.8545414805412292
Done!

Running Predictions on Model…

2020-02-21 20:57:38.879578: W tensorflow/core/common_runtime/base_collective_executor.cc:217] BaseCollectiveExecutor::StartAbort Out of range: End of sequence
[[{{node IteratorGetNext}}]]
Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 46.33% | Actual outcome: RELAXED

Predicted relaxation level: 26.65% | Actual outcome: RELAXED

Predicted relaxation level: 46.43% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 92.04% | Actual outcome: RELAXED

Predicted relaxation level: 8.23% | Actual outcome: NOT RELAXED

Predicted relaxation level: 46.43% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 0.01% | Actual outcome: NOT RELAXED

Predicted relaxation level: 91.67% | Actual outcome: RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 50.64% | Actual outcome: RELAXED

Predicted relaxation level: 44.01% | Actual outcome: NOT RELAXED

Predicted relaxation level: 6.16% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 1.28% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 46.23% | Actual outcome: NOT RELAXED

Predicted relaxation level: 8.29% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 50.51% | Actual outcome: RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 6.24% | Actual outcome: NOT RELAXED

Predicted relaxation level: 6.21% | Actual outcome: RELAXED

Predicted relaxation level: 46.43% | Actual outcome: NOT RELAXED

Predicted relaxation level: 81.17% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 6.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 91.34% | Actual outcome: RELAXED

Predicted relaxation level: 46.63% | Actual outcome: RELAXED

Predicted relaxation level: 46.24% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 46.58% | Actual outcome: NOT RELAXED

Predicted relaxation level: 50.51% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 91.53% | Actual outcome: RELAXED

Predicted relaxation level: 92.12% | Actual outcome: NOT RELAXED

Predicted relaxation level: 46.34% | Actual outcome: RELAXED

Predicted relaxation level: 13.53% | Actual outcome: NOT RELAXED

Predicted relaxation level: 90.99% | Actual outcome: RELAXED

Predicted relaxation level: 46.67% | Actual outcome: RELAXED

Totalling 40/50 generally on the right track with the predictions.

So that’s pretty reasonable, I need to tweak the settings at some point a bit further, but for now these are fairly decent results that are recreatable and reasonably consistent with the test-runner.

PipelineRunnerReal

First results from real EEG set:

Test Loss 0.729458287358284, Test Accuracy 0.9105960130691528
Done!

Running Predictions on Model…

2020-02-18 21:59:41.875691: W tensorflow/core/common_runtime/base_collective_executor.cc:217] BaseCollectiveExecutor::StartAbort Out of range: End of sequence
[[{{node IteratorGetNext}}]]
Predicted relaxation level: 43.77% | Actual outcome: NOT RELAXED

Predicted relaxation level: 74.09% | Actual outcome: RELAXED

Predicted relaxation level: 25.71% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.05% | Actual outcome: NOT RELAXED

Predicted relaxation level: 78.86% | Actual outcome: RELAXED

Predicted relaxation level: 34.37% | Actual outcome: NOT RELAXED

Predicted relaxation level: 71.40% | Actual outcome: RELAXED

Predicted relaxation level: 15.63% | Actual outcome: NOT RELAXED

Predicted relaxation level: 35.14% | Actual outcome: NOT RELAXED

Predicted relaxation level: 92.93% | Actual outcome: NOT RELAXED

Predicted relaxation level: 37.49% | Actual outcome: NOT RELAXED

Predicted relaxation level: 29.67% | Actual outcome: NOT RELAXED

Predicted relaxation level: 44.10% | Actual outcome: NOT RELAXED

Predicted relaxation level: 92.48% | Actual outcome: RELAXED

Predicted relaxation level: 73.76% | Actual outcome: RELAXED

Predicted relaxation level: 40.67% | Actual outcome: NOT RELAXED

Predicted relaxation level: 5.46% | Actual outcome: NOT RELAXED

Predicted relaxation level: 77.27% | Actual outcome: RELAXED

Predicted relaxation level: 84.70% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 89.17% | Actual outcome: RELAXED

Predicted relaxation level: 77.66% | Actual outcome: RELAXED

Predicted relaxation level: 81.35% | Actual outcome: RELAXED

Predicted relaxation level: 76.97% | Actual outcome: RELAXED

Predicted relaxation level: 43.19% | Actual outcome: NOT RELAXED

Predicted relaxation level: 70.66% | Actual outcome: RELAXED

Predicted relaxation level: 79.35% | Actual outcome: RELAXED

Predicted relaxation level: 34.59% | Actual outcome: NOT RELAXED

Predicted relaxation level: 18.56% | Actual outcome: NOT RELAXED

Predicted relaxation level: 41.35% | Actual outcome: NOT RELAXED

Predicted relaxation level: 99.99% | Actual outcome: RELAXED

Predicted relaxation level: 93.98% | Actual outcome: RELAXED

Predicted relaxation level: 77.95% | Actual outcome: RELAXED

Predicted relaxation level: 77.76% | Actual outcome: RELAXED

Predicted relaxation level: 31.27% | Actual outcome: NOT RELAXED

Predicted relaxation level: 78.86% | Actual outcome: NOT RELAXED

Predicted relaxation level: 79.47% | Actual outcome: RELAXED

Predicted relaxation level: 93.80% | Actual outcome: RELAXED

Predicted relaxation level: 0.03% | Actual outcome: NOT RELAXED

Predicted relaxation level: 3.85% | Actual outcome: NOT RELAXED

Predicted relaxation level: 32.03% | Actual outcome: NOT RELAXED

Predicted relaxation level: 84.88% | Actual outcome: RELAXED

Predicted relaxation level: 82.69% | Actual outcome: RELAXED

Predicted relaxation level: 19.66% | Actual outcome: NOT RELAXED

Predicted relaxation level: 8.53% | Actual outcome: NOT RELAXED

Predicted relaxation level: 81.61% | Actual outcome: RELAXED

Predicted relaxation level: 6.60% | Actual outcome: NOT RELAXED

Predicted relaxation level: 83.50% | Actual outcome: RELAXED

Predicted relaxation level: 41.63% | Actual outcome: NOT RELAXED

Predicted relaxation level: 76.82% | Actual outcome: RELAXED

Totalling 47/50 generally on the money with the predictions. Another attempt yielded similar results.

 

I tried some more tests and found that the 30 seconds per CSV batch of mind data wasn’t always accurate so I decided to raised it to 2 minutes and a run from that resulted in:

Test Loss 0.434320068359375, Test Accuracy 0.7653399705886841
Done!

Running Predictions on Model…

2020-02-21 22:08:07.551755: W tensorflow/core/common_runtime/base_collective_executor.cc:217] Bas eCollectiveExecutor::StartAbort Out of range: End of sequence
[[{{node IteratorGetNext}}]]
Predicted relaxation level: 3.55% | Actual outcome: NOT RELAXED

Predicted relaxation level: 36.90% | Actual outcome: RELAXED

Predicted relaxation level: 1.24% | Actual outcome: NOT RELAXED

Predicted relaxation level: 52.69% | Actual outcome: RELAXED

Predicted relaxation level: 0.01% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.44% | Actual outcome: NOT RELAXED

Predicted relaxation level: 35.82% | Actual outcome: RELAXED

Predicted relaxation level: 67.30% | Actual outcome: RELAXED

Predicted relaxation level: 61.27% | Actual outcome: RELAXED

Predicted relaxation level: 0.03% | Actual outcome: NOT RELAXED

Predicted relaxation level: 11.89% | Actual outcome: RELAXED

Predicted relaxation level: 84.09% | Actual outcome: RELAXED

Predicted relaxation level: 45.33% | Actual outcome: RELAXED

Predicted relaxation level: 83.76% | Actual outcome: RELAXED

Predicted relaxation level: 84.47% | Actual outcome: RELAXED

Predicted relaxation level: 0.11% | Actual outcome: NOT RELAXED

Predicted relaxation level: 47.62% | Actual outcome: RELAXED

Predicted relaxation level: 0.04% | Actual outcome: NOT RELAXED

Predicted relaxation level: 22.17% | Actual outcome: RELAXED

Predicted relaxation level: 1.19% | Actual outcome: NOT RELAXED

Predicted relaxation level: 77.79% | Actual outcome: RELAXED

Predicted relaxation level: 31.63% | Actual outcome: NOT RELAXED

Predicted relaxation level: 56.86% | Actual outcome: RELAXED

Predicted relaxation level: 4.79% | Actual outcome: NOT RELAXED

Predicted relaxation level: 84.44% | Actual outcome: RELAXED

Predicted relaxation level: 30.84% | Actual outcome: RELAXED

Predicted relaxation level: 0.37% | Actual outcome: NOT RELAXED

Predicted relaxation level: 81.39% | Actual outcome: RELAXED

Predicted relaxation level: 0.89% | Actual outcome: NOT RELAXED

Predicted relaxation level: 66.95% | Actual outcome: RELAXED

Predicted relaxation level: 40.20% | Actual outcome: NOT RELAXED

Predicted relaxation level: 84.41% | Actual outcome: RELAXED

Predicted relaxation level: 36.15% | Actual outcome: NOT RELAXED

Predicted relaxation level: 82.13% | Actual outcome: RELAXED

Predicted relaxation level: 85.40% | Actual outcome: RELAXED

Predicted relaxation level: 6.47% | Actual outcome: NOT RELAXED

Predicted relaxation level: 80.10% | Actual outcome: NOT RELAXED

Predicted relaxation level: 75.26% | Actual outcome: RELAXED

Predicted relaxation level: 82.98% | Actual outcome: RELAXED

Predicted relaxation level: 0.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 0.03% | Actual outcome: NOT RELAXED

Predicted relaxation level: 60.53% | Actual outcome: RELAXED

Predicted relaxation level: 21.79% | Actual outcome: RELAXED

Predicted relaxation level: 0.87% | Actual outcome: NOT RELAXED

Predicted relaxation level: 18.36% | Actual outcome: RELAXED

Predicted relaxation level: 69.78% | Actual outcome: RELAXED

Predicted relaxation level: 5.55% | Actual outcome: NOT RELAXED

Predicted relaxation level: 83.83% | Actual outcome: RELAXED

Predicted relaxation level: 11.75% | Actual outcome: NOT RELAXED

Predicted relaxation level: 39.90% | Actual outcome: RELAXED

39/50 Generally on the money with less loss. Again though it’s not easy to tell with this kind of data as it can be hard to keep the mind relaxed during the relaxed data gathering parts.

Here’s another set of results from real EEG data (2 minutes per set of mind data):

Test Loss 0.4204348623752594, Test Accuracy 0.8781094551086426
Done!

Running Predictions on Model…

2020-02-21 23:04:29.122701: W tensorflow/core/common_runtime/base_collective_executor.cc:217] BaseCollectiveExecutor::StartAbort Out of range: End of sequence
[[{{node IteratorGetNext}}]]
Predicted relaxation level: 11.08% | Actual outcome: NOT RELAXED

Predicted relaxation level: 79.37% | Actual outcome: RELAXED

Predicted relaxation level: 11.40% | Actual outcome: NOT RELAXED

Predicted relaxation level: 10.88% | Actual outcome: RELAXED

Predicted relaxation level: 72.23% | Actual outcome: RELAXED

Predicted relaxation level: 80.06% | Actual outcome: NOT RELAXED

Predicted relaxation level: 79.83% | Actual outcome: RELAXED

Predicted relaxation level: 82.37% | Actual outcome: RELAXED

Predicted relaxation level: 91.75% | Actual outcome: RELAXED

Predicted relaxation level: 14.45% | Actual outcome: NOT RELAXED

Predicted relaxation level: 11.17% | Actual outcome: NOT RELAXED

Predicted relaxation level: 92.58% | Actual outcome: RELAXED

Predicted relaxation level: 14.87% | Actual outcome: NOT RELAXED

Predicted relaxation level: 86.09% | Actual outcome: RELAXED

Predicted relaxation level: 84.20% | Actual outcome: RELAXED

Predicted relaxation level: 60.79% | Actual outcome: RELAXED

Predicted relaxation level: 55.60% | Actual outcome: RELAXED

Predicted relaxation level: 1.13% | Actual outcome: RELAXED

Predicted relaxation level: 83.39% | Actual outcome: RELAXED

Predicted relaxation level: 88.20% | Actual outcome: RELAXED

Predicted relaxation level: 19.61% | Actual outcome: NOT RELAXED

Predicted relaxation level: 10.73% | Actual outcome: NOT RELAXED

Predicted relaxation level: 21.90% | Actual outcome: NOT RELAXED

Predicted relaxation level: 13.40% | Actual outcome: NOT RELAXED

Predicted relaxation level: 80.20% | Actual outcome: NOT RELAXED

Predicted relaxation level: 36.91% | Actual outcome: NOT RELAXED

Predicted relaxation level: 11.53% | Actual outcome: NOT RELAXED

Predicted relaxation level: 11.05% | Actual outcome: NOT RELAXED

Predicted relaxation level: 39.89% | Actual outcome: RELAXED

Predicted relaxation level: 10.54% | Actual outcome: NOT RELAXED

Predicted relaxation level: 83.29% | Actual outcome: RELAXED

Predicted relaxation level: 12.89% | Actual outcome: NOT RELAXED

Predicted relaxation level: 79.31% | Actual outcome: RELAXED

Predicted relaxation level: 35.32% | Actual outcome: NOT RELAXED

Predicted relaxation level: 79.81% | Actual outcome: RELAXED

Predicted relaxation level: 80.30% | Actual outcome: NOT RELAXED

Predicted relaxation level: 41.01% | Actual outcome: NOT RELAXED

Predicted relaxation level: 79.44% | Actual outcome: RELAXED

Predicted relaxation level: 14.18% | Actual outcome: NOT RELAXED

Predicted relaxation level: 11.48% | Actual outcome: NOT RELAXED

Predicted relaxation level: 14.81% | Actual outcome: NOT RELAXED

Predicted relaxation level: 86.93% | Actual outcome: RELAXED

Predicted relaxation level: 71.70% | Actual outcome: RELAXED

Predicted relaxation level: 82.02% | Actual outcome: RELAXED

Predicted relaxation level: 14.59% | Actual outcome: NOT RELAXED

Predicted relaxation level: 10.55% | Actual outcome: NOT RELAXED

Predicted relaxation level: 52.01% | Actual outcome: RELAXED

Predicted relaxation level: 83.47% | Actual outcome: RELAXED

Predicted relaxation level: 85.90% | Actual outcome: RELAXED

Predicted relaxation level: 83.63% | Actual outcome: RELAXED

Done!

42/50 that time – pretty good and showing these are consistent results coming in, this time I used timers to help me know when the time was up per reading session, so I could fully close my eyes and empty my mind, seems to work nicely.

 

I also tried it with the headset off a couple of times to check the above wasn’t a fluke, as expected the results were random as the headset was picking up no actual EEG data from my head:

Test Loss 39.88598098754883, Test Accuracy 0.3905472755432129
Done!

Running Predictions on Model…

2020-02-21 23:19:40.160813: W tensorflow/core/common_runtime/base_collective_executor.cc:217] BaseCollectiveExecutor::StartAbort Out of range: End of sequence
[[{{node IteratorGetNext}}]]
Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 56.57% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 99.47% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 22.53% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 23.73% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 63.67% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 15.41% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 99.89% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 12.77% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 22.10% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 13.01% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Predicted relaxation level: 100.00% | Actual outcome: NOT RELAXED

Predicted relaxation level: 100.00% | Actual outcome: RELAXED

Again, as expected – random results as there was no real differing data coming from the EEG headset sensors.

All of these results are similar to the results I found in my video:

I have noticed the error above:

tensorflow/core/common_runtime/base_collective_executor.cc:217] BaseCollectiveExecutor::StartAbort Out of range: End of sequence
[[{{node IteratorGetNext}}]]

Something I need to look into.

Conclusion and Onward

I’m very happy with how this went and that it actually worked – I just need to do some further research into optimising models and data while also getting a ton more real world EEG data to train on.

Getting the real world EEG training data was a little difficult as sometimes it can be difficult to focus my mind and get it to relax, upping to 2 minutes per batch of data seemed to improve things, so there’s definitely more to investigate there as well.

I could be using the wrong method on the batching – maybe it’s harming the data flicking my mind between relaxed states and non-relaxed so fast and the transition isn’t as smooth or as fast for the mind. It’s going to take some more experimentation.

The way the code is written and separated is done to allow testing of each individual module, however you can’t manually step through the process at the moment. IE. step through data gathered then importing then training, inference etc. by calling one script at a time – this will be possible in future when I will be actually saving the model to a file.

Hopefully then I can amass huge amounts of data on relaxed and non-relaxed mind sets and train the model better – this will be where I will probably have to look into more efficient optimiser settings and sorting out the different layers of the network to handle the data better.

Then I’ll make it so it can save the model and then have that be loaded into a real-time analyser application – once I’ve done that and learnt a lot more about TensorFlow I will try and move onto gathering much much more real world data and try and distinguish more than just 2 mind-states.

Once I have lots and lots of data I can then start moving onto somehow building models around the models and abstracting up to try and use the data in some kind of AI style application. Not entirely sure how I’ll do this yet but I’m excited to see what can be done and what else can be determined.

There are also other sensors on board the Muse that I am currently not using such as heart rate etc. This should provide more data and hopefully increase accuracy as well as open up the opportunity to find more mind states – again which can then be loaded into an application for reading real time data.

With enough luck and determination I’m hoping this is the beginning to being able to detect many different types of mindset and being able to train models on them.

At the moment this isn’t meant to be a perfect and complete project but rather the beginning steps to something bigger; a learning and R&D experience, so please feel free to let me know if there’s something I can improve.

My intention is to build up and up increasing the complexity of whats being measured and learnt as well as trying to get more advanced sensor tech so that one day, eventually I can transfer my mind into a computer…

Image result for ross geller transfer mind into a machine
Thanks, Ross.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s