{"id":13744538,"url":"https://github.com/Sentdex/BCI","last_synced_at":"2025-05-09T03:32:32.530Z","repository":{"id":48157684,"uuid":"220845707","full_name":"Sentdex/BCI","owner":"Sentdex","description":"Brain-Computer interface stuff","archived":false,"fork":false,"pushed_at":"2022-10-25T08:34:58.000Z","size":12072,"stargazers_count":310,"open_issues_count":4,"forks_count":73,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-07T07:18:30.037Z","etag":null,"topics":["bci","brain-computer-interface"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sentdex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-10T20:16:55.000Z","updated_at":"2025-04-07T02:14:19.000Z","dependencies_parsed_at":"2023-01-20T11:17:24.139Z","dependency_job_id":null,"html_url":"https://github.com/Sentdex/BCI","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sentdex%2FBCI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sentdex%2FBCI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sentdex%2FBCI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sentdex%2FBCI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sentdex","download_url":"https://codeload.github.com/Sentdex/BCI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253183214,"owners_count":21867382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bci","brain-computer-interface"],"created_at":"2024-08-03T05:01:11.387Z","updated_at":"2025-05-09T03:32:30.909Z","avatar_url":"https://github.com/Sentdex.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"![OpenBCI Headset](https://pythonprogramming.net/static/images/bci/openbciheadset.png)\n\n# Brain-Computer Interface workspace\n\nMy objective here is to share some of the code, models, and data from the OpenBCI 16-channel headset. I suspect many people are not going to be able to get their hands on the headset, but that doesn't mean you can't still play with some of the data!\n\nHeadset used is the OpenBCI Ultracortex Mark IV. You can check out OpenBCI's products here: https://shop.openbci.com/\n\n\n# Objectives\n\nTo start, my objective is to train a neural network to detect thoughts of left/right movements. From here, I would like to apply this BCI control to GTA V \n\n\n# Files\n`training.py` - This is merely an example of training a model with this data. I have yet to find any truly great model, though at the end of this readme, I will try to keep an updated confusion matrix of my best-yet models. This way, you can easily tell if you've been able to find something better than what I've got. \n\nIf people are able to beat my model and are willing to share their models. I will post some sort of highscores somewhere on this repo.\n\nSince some people wont be able to resist making a model on validation data...I will use my own separate validation data to actually create scores. If you're not cheating, this shouldn't impact you ;)\n\n\n`analysis.py` - You can use this to run through validation data to see confusion matricies for your models on out of sample data.\n\nExample of a % accuracy confusion matrix (the default graphed):\n![confusion matrix](https://pythonprogramming.net/static/images/bci/model_conf_matrix.png)\nModel used for the above: https://github.com/Sentdex/BCI/tree/master/models#614-acc-loss-239-topmodel\n\nIn the above confusion matrix, we can see that if the thought is left, the model accurately predicts this 53% of the time, predicts that left thought is actually none 15% of the time, and predicts right 32% of the time. \n\nFor the \"right\" thought, we can see the model predicted that correctly 64% of the time, predicted none 16% of the time, and predicted left 21% of the time.\n\nAn \"ideal\" confusion matrix would be a perfectly green diagonal line of boxes from the top left to the bottom right. This isn't too bad so far. \n\n\n`testing_and_making_data.py` - This is just here if you happen to have your own OpenBCI headset and want to actually play with the model and/or build on the dataset. Or if you just want to help audit/improve my code. This file will load in whatever model you wish to use, you will specify the action you intend to think ahead of time for the `ACTION` var, then you run the script. The environment will pop up and collect all of your FFT data, storing them to a numpy file in the dir named whatever you said the `ACTION` thought was.\n\n\n# Requirements\nNumpy\nTensorFlow 2.0. (you need 2.0 if you intend to load the models)\npylsl (if you intend to run on an actual headset)\nOpenBCI GUI (using the networking tab https://docs.openbci.com/docs/06Software/01-OpenBCISoftware/GUIDocs)\n\n\n\n# The data\n\nCurrently, the data available is 16-channel FFT 0-60Hz, sampled at a rate of about 25/second. Data is contained in directories labeled as `left`, `right`, or `none`. These directories contain numpy arrays of this FFT data collected where I was thinking of moving a square on the screen in this directions. \n\nI am not sure where I want to put the data, but, for now, it's available here: \n\u003cstrong\u003eDownload:\u003c/strong\u003e https://hkinsley.com/static/downloads/bci/model_data_v2.7z\n\nI plan to upload more and more as I create more data.\n\n*File structure (for both the data and validation_data directories)*: \n\u003cul\u003e\n\t\u003cli\u003edata\n\t\t\u003cul\u003e\n\t\t\t\u003cli\u003eleft\u003c/li\u003e\n\t\t\t\u003cli\u003enone\u003c/li\u003e\n\t\t\t\u003cli\u003eright\u003c/li\u003e\n\t\t\u003c/ul\u003e\n\t\u003c/li\u003e\n\t\u003cli\u003evalidation_data\n\t\t\u003cul\u003e\n\t\t\t\u003cli\u003eleft\u003c/li\u003e\n\t\t\t\u003cli\u003enone\u003c/li\u003e\n\t\t\t\u003cli\u003eright\u003c/li\u003e\n\t\t\u003c/ul\u003e\n\t\u003c/li\u003e\n\u003c/ul\u003e\n \nContained within the left, none, and right directories are `.npy` files with unix timestamps as their name. Each of the files is a numpy array of shape: \n```py\nimport numpy as np\n\nd = np.load(\"data/left/1572814991.npy\")\nprint(d.shape)\n\n\u003e\u003e\u003e(250, 16, 60)\n```\n\nEach file is targeted to be 10 seconds long, which, at 25 iter/sec gives us, the 250 (though you should not depend/assume all files will be exactly 250 long). Then you have the number of channels (16), and then 60 values, for up to 60Hz. For example, if you do: \n\n```py\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nd = np.load(\"data/left/1572814991.npy\")\n\nplt.plot(d[0][0])\nplt.show()\n```\n\nYou will see a graph of: The data for Channel 0 for the very first sample.\n![FFT graph single channel](https://pythonprogramming.net/static/images/bci/fft-single-channel.png)\n\nIf you want to see all 16 channels:\n```py\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nd = np.load(\"data/left/1572814991.npy\")\n\nfor channel in d[175]:\n    plt.plot(channel)\nplt.show()\n```\n![FFT graph 16 channels](https://pythonprogramming.net/static/images/bci/fft-16-channels.png)\n\n\n# Best model so far (on the validation/out of sample data):\n![confusion matrix](https://pythonprogramming.net/static/images/bci/currentbest.png)\n\nMore info: https://github.com/Sentdex/BCI/tree/master/models#all-cnn-model-6323-acc-loss-252model\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSentdex%2FBCI","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSentdex%2FBCI","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSentdex%2FBCI/lists"}