Giter VIP home page Giter VIP logo

eeglearn's People

Contributors

pbashivan avatar yilinjuang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eeglearn's Issues

AssertionError: features.shape[1] % nElectrodes == 0

When I run the ** eeg_cnn_lib.py ** script. This AssertionError Pops Up:
AssertionError: features.shape[1] % nElectrodes == 0

With:
features.shape[1] -> 31
nElectrodes -> 10

As far as I understand from the comments in the Code the shape of features is [n_saples, n_features + 1].

So a fix in gen_images [line: 41] could be:
n_features = features.shape[1] - 1

# Test whether the feature vector length is divisible by number of electrodes (last column is the labels)
assert n_features % nElectrodes == 0
n_colors = n_features / nElectrodes

Is my understanding correct?

Test performance

The code "eeg_cnn_lib.py" looks like: it loads data from "Sample data" folder, converts the data to 2D images, then create 5 models, but doesn't train the data. Do you have code for training and test set prediction?

Data files

Thank you for your previous replies. I read your paper and also understand the procedure. Able to run your program end to end. But not able to figure out how to generate those data files - if i am using different data sets.

Sample data folder location:
https://github.com/pbashivan/EEGLearn/tree/master/Sample%20data

But i would like to know how the below files formed (As i am trying with different data sets)

FeatureMat_timeWin.mat
Neuroscan_locs_orig.mat
trials_subNums.mat

Some questions about imshow

@pbashivan Dear prof, I'm a student from Taiwan, I've some question want to ask you:

I've same error like#27, so I fix eeg_cnn_lib.py that can run and train in python 3.5.4 . When it done, I've weights_lasg_cnn.npz and weights_lasg_mix.npz file, but I can't see any images even I use matplotlib to plot.
After I check error msg it said: Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).

I want to know how to solve these problem, I am looking forward to your feedback at your earliest convenience.
Thank you

Applying EEGLearn on EEG Motor Movement/Imagery Dataset

I am trying to use the network to classify Motor Movement but this network works very well on the author's example data but doesn't work on new data.

Actually, I am using the "EEG Motor Movement/Imagery Dataset" (https://www.physionet.org/content/eegmmidb/1.0.0/) and it's a popular dataset, other people arrived at ~80 % accuracy and I got this accuracy with brain decode (CNN - https://tntlfreiburg.github.io/braindecode/). Now, I am trying to classify this data using EEGLearn (RNN-CNN https://github.com/YangWangsky/tf_EEGLearn) but I'm still on the chance level. Do you have any suggestions?

electrodes 10-20 problem

Hi,

It's lucky to known the nice package. We have encountered a problem by matching the FFT signal with elect, electrodes position from 10-20 coordinates for newborn.

We used 4 electrodes here since the baby's brain surface is not big enough. The bi-channel (e.g c3-c4,p3-p4) signal is measured by comparing two electrodes for theta, alpha and beta.

Can we use the coordinates centre for C3 and P3 for 29th line here? Or is there a way to adopt your models?

Thanks,
Best

Channel to position information

Hi,

I am currently working on a project where I want to have standard electrode positions (I am following https://arxiv.org/abs/1608.00220 which is inspired by your paper).
However, when I open your file containing the electrode positions ("Sample data/Neuroscan_locs_orig.mat"), I can't find the name of the channel corresponding to the position indicated.

Do you know if there is an easy way to retrieve this information?

Thanks again for your work

nice work

do you think thid can be used with the Muse Headband?

There are some problems running the code

Hello, dear professor, I have run your code on the school's server, and I have configured the Theano environment that I need, but every time I run the code, the school's server suddenly fails to connect. What do you think about this problem? Suggest? For example, should I configure a Theano gpu environment? And I want to use your code on the CHB-MIT data set, but I don’t know how to process the EEG data of patients with epilepsy. Do you have any recommended books or courses? Looking forward to your reply.

Which electrode corresponds to the three-dimensional coordinates

Dear Professor, is the 64-lead electrode mentioned in the text agreed upon in quik-cap?
The three-dimensional coordinates in the coordinate file of the electrode in the project, which electrode corresponds to which?
Please help me solve the problem at a convenient time.

GPU Acceleration?

Hi!

Thanks for this, especially the sample code. I'm new here and this has been a great introduction to EEG and deep neural networks.

Does this code tap on the GPU, e.g. via CUDA/cuDNNs? I have a mid-range Nvidia GPU on my laptop, and when running previous deep learning programmes using PyTorch on a Jupyter Notebook, I have been able to successfully speed up training times by about 5 times using CUDA.

It doesn't seem like this code does, but I'd just like to check with you because I don't have much experience! Thanks.

Best regards,
Michelle

the sample data structure

the FeatureMat_timeWin.mat in your sample dataset have a ndarray and shape= (2760,1344),so,what is 1344? And where is the 64 electrodes channels signal ?

Sample Code

Hello there!
I am new to this stuff.

Do you have any sample code for using it on any publicly available database which I can follow to understand how your library can be used?

I am just starting in this field and have very limited theoretical knowledge. I am trying to find code that I can run on the given data and it classifies it so I can understand it and use it on my data later

can you please upload training code for sample data?

do you have the training code?
I tried the following code:

import eeglearn
import eeglearn.eeg_cnn_lib as eeglib
import scipy.io as sio
locs = sio.loadmat('/home/anindya/Projects/EEGLearn-master/Sample data/Neuroscan_locs_orig.mat')
locs_a = locs['A']
features = sio.loadmat('/home/anindya/Projects/EEGLearn-master/Sample data/FeatureMat_timeWin.mat')
features_a = features['features']
images = eeglib.gen_images(locs_a, features_a, 1024)

but it is giving the assertion error in gen_images function

applied the baseline correction?

Hello, dear author, I would like to know whether you have applied the baseline correction method?
In other words, does the average power obtained subtract the average power before the mark?

Python module version? What are the versions of each module that you used?

File "C:\Users\myUser\AppData\Local\Continuum\anaconda2\lib\site-packages\lasagne_init_.py", line 17, in
from . import nonlinearities

ImportError: cannot import name nonlinearities

I am wonder are there any other specific requirements to run your code(e.g. specific modules version, python environment)? Can you kindly write a demo to show how to run your code? I really want to try out your method on my EEG data. Really appreciate!

What form of data should be given?

Hi
I would like to generate EEG images using other data (DEAP dataset).
But, I have parts that I can not understand in your code.

images = eeglib.gen_images(np.array(locs_2d), features, nGridPoints)

I saw "eeg_cnn_lib.py", but I couldn't understand "features" given as a features.
What form of data should be given?

dimention of FeatureMat_timeWin.mat

this file (FeatureMat_timeWin.mat) has shape (2670,1345). 2670 is the number of subjects. but from where 1345 is coming?the last column (i.e. 1345th one is for classification levels)but how you are getting the number 1344?
what I understand is that for each EEG signal (ONE OF 64 EEG SIGNAL) I have to take FFT and then get the spectral power for each of the three frequency band.So I will be getting 3 different values for three different frequency bands.So, ultimately I will be getting 64 values for one subject trial and for one frequency band.
please correct me If my understanding is wrong?and I want to know how you are getting that feature matrix with the number of column 1345?

Questions about training parameters

Hello professor!
Now I'm running this code using pytorch.It confuses me that if I want to reach your performance what batch size I should set.Because useing VDelv's code and cross validation 13 can not reach your performance.In your paper you said that batch size is 20,but This code I see that is 32.
I use parameters: batch size = 32, num_epoch = 10 and optimizer is Adam, learning rate = 0.001 ,and result is
0.6 0.825 0.88 0.98 0.99 1 0.97 0.99 0.99 0.97 0.27 0.81 0.67
and your parper results is
0.889 0.765 0.933 0.99 1 0.98 1 0.985 0.99 0.968 0.965 0.91 0.468

Hope to hear from you soon.
Thank you very much.

ValueError: Unknown interpolation method 'cubic' for 3 dimensional data

Hi,

I am getting the following error and was wondering if you could help me fix it. I am using the sample data you provided.

Thanks!
-Maciej

Traceback (most recent call last):
  File "C:/Users/Christine/PycharmProjects/EEG_VM/main.py", line 15, in <module>
    images = eeglib.gen_images(locs, features, nGridPoints)
  File "C:\Users\Christine\Anaconda3\envs\EEG_VM\lib\site-packages\eeglearn\eeg_cnn_lib.py", line 96, in gen_images
    method='cubic', fill_value=np.nan)
  File "C:\Users\Christine\Anaconda3\envs\EEG_VM\lib\site-packages\scipy\interpolate\ndgriddata.py", line 225, in griddata
    "%d dimensional data" % (method, ndim))
ValueError: Unknown interpolation method 'cubic' for 3 dimensional data

main.py

import eeglearn
import eeglearn.eeg_cnn_lib as eeglib
import numpy as np

import scipy.io as sio # need this to load mat files

# load data
locs_raw = sio.loadmat("./sample_data/Neuroscan_locs_orig.mat")
locs = locs_raw['A']
features_raw = sio.loadmat("./sample_data/FeatureMat_timeWin.mat")
features = features_raw['features']
features = features[:, 0:-1] # remove the last column; otherwise, assert features.shape[1] % nElectrodes == 0  gives AssertionError
nGridPoints = 100

images = eeglib.gen_images(locs, features, nGridPoints)
eeglib.train(images, labels, train_test_fold, model_type)

EEGLearn_files.zip

Problem plotting images

Dear Professor:

I've been working with your library and I've got a problem. Here's the error:

Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).

How can I rescale to 0-255 interval?

Greetings

Save Predictions

Hello pbashivan @p

I am trying to save predictions ( predicted values and true values) either as .mat file or .npy file. however, i can't find on the internet how can i saved in theano/lasagne? can you help me with that?

Thank You

a question about Sample Data

what is the sense of 1345th columns in Sample data/FeatureMat_timeWin.mat? I read the whole code,and i find this columns is not used.In my view, the label is recorded in trials_subNums.mat, right?

Error in "Starting Training session'

Hi everyone,
very interesting work. I am trying to use it with my dataset. I create the features matrix just like your, but in my case it is [2696 1603] ( I have 2696 example of 3 classes, 89 channels, 3 frequency bands and 6 time windows). I got the following error and I don't know how to fix it. Can anyone help me please?
Thanks a lot

ValueError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\theano\compile\function_module.py in call(self, *args, **kwargs)
902 outputs =
--> 903 self.fn() if output_subset is None else
904 self.fn(output_subset=output_subset)

ValueError: y_i value out of bounds

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
in ()
1 # Class labels should start from 0
2 print('Training the CNN Model...')
----> 3 train(images, np.squeeze(feats[:, -1]) - 1, fold_pairs[2], 'cnn')

in train(images, labels, fold, model_type, batch_size, num_epochs)
398 for batch in iterate_minibatches(X_train, y_train, batch_size, shuffle=False):
399 inputs, targets = batch
--> 400 train_err += train_fn(inputs, targets)
401 train_batches += 1
402 # And a full pass over the validation data:

~\Anaconda3\lib\site-packages\theano\compile\function_module.py in call(self, *args, **kwargs)
915 node=self.fn.nodes[self.fn.position_of_error],
916 thunk=thunk,
--> 917 storage_map=getattr(self.fn, 'storage_map', None))
918 else:
919 # old-style linkers raise their own exceptions

~\Anaconda3\lib\site-packages\theano\gof\link.py in raise_with_op(node, thunk, exc_info, storage_map)
323 # extra long error message in that case.
324 pass
--> 325 reraise(exc_type, exc_value, exc_trace)
326
327

~\Anaconda3\lib\site-packages\six.py in reraise(tp, value, tb)
690 value = tp()
691 if value.traceback is not tb:
--> 692 raise value.with_traceback(tb)
693 raise value
694 finally:

~\Anaconda3\lib\site-packages\theano\compile\function_module.py in call(self, *args, **kwargs)
901 try:
902 outputs =
--> 903 self.fn() if output_subset is None else
904 self.fn(output_subset=output_subset)
905 except Exception:

ValueError: y_i value out of bounds
Apply node that caused the error: CrossentropySoftmaxArgmax1HotWithBias(Dot22.0, b, targets)
Toposort index: 106
Inputs types: [TensorType(float64, matrix), TensorType(float64, vector), TensorType(int32, vector)]
Inputs shapes: [(32, 3), (3,), (32,)]
Inputs strides: [(24, 8), (8,), (4,)]
Inputs values: ['not shown', array([0., 0., 0.]), 'not shown']
Outputs clients: [[Sum{acc_dtype=float64}(CrossentropySoftmaxArgmax1HotWithBias.0)], [CrossentropySoftmax1HotWithBiasDx(Elemwise{Inv}[(0, 0)].0, CrossentropySoftmaxArgmax1HotWithBias.1, targets)], []]

HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

Classification Results for each fold

Hi pbashivan,
How to calculate the Table – 4 i.e. classification results for each subjects? Please give me some hints. Which module does this job(On your program eeg_cnn_lib.py)?

downsample issue

Hi pbashivan,

I am getting below error. I thinking i have installed everything correct. Please help on this and struct

Using gpu device 0: Tesla K40c (CNMeM is disabled, cuDNN 5110)
Traceback (most recent call last):
File "/home/shiba/Desktop/Note/EEGLearn-master/eeglearn/eeg_cnn_lib.py", line 17, in
import lasagne
File "/home/shiba/anaconda2/lib/python2.7/site-packages/lasagne/init.py", line 24, in
from . import layers
File "/home/shiba/anaconda2/lib/python2.7/site-packages/lasagne/layers/init.py", line 7, in
from .pool import *
File "/home/shiba/anaconda2/lib/python2.7/site-packages/lasagne/layers/pool.py", line 6, in
from theano.tensor.signal import downsample
ImportError: cannot import name downsample

The images show

Dear Prof,
Sorry to disturb you,how can i modify the program to make the image show?Thank you sir!

questions

@BashivanLab Dear professor, I still have a few questions:

  1. When generating the data set, does the order of the three-dimensional coordinates of the electrode correspond to the coordinate index of each frequency band in Neuroscan_locs_orig?
  2. I extract the power spectrum of each frequency band to find the average power, then follow the method in step 1 to generate a data set, and finally generate an image. Does the white area in the image mean that all three frequency bands are active? Does more color area in which frequency band mean that the frequency band is more active?
  3. https://github.com/wangyue663/images/blob/main/E%24NI8C%7DGFD(NF%4036OSP0%7D2N.png
    This is the picture I generated, basically every picture has a black part, Is this normal?
    thank you very much!

The function azim_proj(pos)

Dear professor:
Thanks for your algorithms.
In the function :
[r, elev, az] = cart2sph(pos[0], pos[1], pos[2])
return pol2cart(az, m.pi / 2 - elev)
I don't understand the second actual parameter m.pi / 2 - elev, I think maybe it should equal to r*(m.pi/2-elev).
Could you please help me understand why there is no r?

Parameters and configuration of the modified version of the Sternberg memory task.

I have a question about the size of the letters in the modified experiment of the memory task of Sternberg that you adopted in your data set, mentions that the size should be 1.15 °. However I do not understand the reference in terms of degrees refers or what kind of measure is, more still defines a visual angle of 2.9 ° this in terms of the issue of location and spacing between characters or with respect to what situation is established measure. Thank you for your attention, I am waiting for your response.

Extracting psd features

Hi,
I have epoched data from EEGLAB. Every epoch has 250 time frames. I'm still not able to extract the frequency features to be as mentioned in your example. The data should be:
(number of samples, number of electrodes * number of frequency bands * number of time windows).
I'm trying in MNE-Python to do this but no way. As a result I'm getting (number of samples , number of electrodes * number of frequency bands). So I'm not able to divide each epoch to windows as it should be. Could you kindly tell me which function do you use. either in EEGLAB or in MNE?
To extract the frequency features, I'm using this code in MNE-Python after getting epoched data from EEGLAB:

def eeg_power_band(epochs):
FREQ_BANDS = {"theta": [4.5, 8.5], "alpha": [8.5, 11.5], "beta": [15.5, 30]}
epochs = epochs.load_data().pick_channels(EEG_CHANNELS).get_data()
psds, freqs = mne.time_frequency.psd_welch(epochs, fmin=0.5, fmax=30.,n_fft=250, n_overlap=0)
# Normalize the PSDs
psds /= np.sum(psds, axis=-1, keepdims=True)
X = []
for _, (fmin, fmax) in FREQ_BANDS.items():
psds_band = psds[:, :, (freqs >= fmin) & (freqs < fmax)].mean(axis=-1)
#X.append(psds_band.reshape(len(psds), -1))
X.append(psds_band)
return np.concatenate(X, axis=1)

Many many thanks in advance

Average power within each frequency band of interest

Hi
I am not able to figure out the below stuff on EEGLAB tool. would you please help on this....I am totally stuck on my experiment and using online data sets

from your previous reply:
at URL - #12
i was advised below stuffs to calculate.


I used the average power within each frequency band of interest. I think this would be a better estimate of the shape of PSD. Taking the max might be noisy.

You can divide the time series into windows and apply FFT on each window or use wavelet transformation on the complete signal and then divide it to windows.

Please help me on this.

Some question about convert 3D point to 2D point

Hi,

Recently, I used the scripts on the sample data. But there is an error as follow:

11111111

So I modified this [r, elev, az] = cart2sph(pos[0], pos[1], pos[2]) return pol2cart(az, m.pi / 2 - elev) to cod = np.zeros((pos.shape[0], 2)) for i in range(pos.shape[0]): [r, elev, az] = cart2sph(pos[i,0], pos[i,1], pos[i,2]) cod[i,:] = pol2cart(az, m.pi / 2 - elev) return cod, then the 3D position points can convert to 2D points as follows:
11111112
But the temp_interp value before normalize is all nan,
[ n an, nan, nan, ..., nan, nan, nan],
[ nan, nan, nan, ..., nan, nan, nan],
[ nan, nan, nan, ..., nan, nan, nan]],

and after normalize the value of temp_interp is all zero. So the network doesn't work after generating images.

Could you help me to solve these problems? Thank you very much.

float' object cannot be interpreted as an integer

Hi,when I run the code,it shows as following:
Loading data...
Generating images...
Traceback (most recent call last):
File "C:/Users/Guo/Desktop/EEGLearn-master/eeglearn/eeg_cnn_lib.py", line 473, in
av_feats = reduce(lambda x, y: x+y, [feats[:, i*192:(i+1)*192] for i in range(feats.shape[1] / 192)])
TypeError: 'float' object cannot be interpreted as an integer

so I modify the part of line 473 as" (feats.shape[1] //192)" ,it shows:
Loading data...
Generating images...
Traceback (most recent call last):
File "C:/Users/Guo/Desktop/EEGLearn-master/eeglearn/eeg_cnn_lib.py", line 477, in
32, normalize=False)
File "C:/Users/Guo/Desktop/EEGLearn-master/eeglearn/eeg_cnn_lib.py", line 67, in gen_images
for c in range(n_colors):
TypeError: 'float' object cannot be interpreted as an integer

would you give me some suggestions?thank you

About the average power in your file "FeatureMat_time"

Dear professor:
In your file "FeatureMat_time", The maximum value of the feature is 51.65, the minimum is -1.05, and the mean value is 0.0017.
But after the FFT using np.fft.fft, the power value is generally between 0 and 100. Therefore, for these features, did you normalize them or log them? I don’t know your specific operation, I hope you can give some specific code about this part.

In addition, about the frequency band, I set the theta (4-7 Hz), alpha (7-13 Hz) and beta (13-30 Hz). But in your experiment, you did not specify the range of these bands. Did you choose the same as mine?

Looking forward to your reply, thank you very much

There is a problem in extracting the 64 eigenvalues of the three frequency domains of the EEG signal

Hello professor, I want to apply the CHB-MIT epilepsy EEG data set to your code, but this data set only has 23 channels and uses 23 brain electrodes, then do I use 23 α, θ, β Is it enough to perform power spectrum estimation after FFT? Power spectrum estimation is to take the square and divide by the length of time after FFT, right? But will there be negative values in the FeatureMat_timeWin table in your Sample data? Thank you very much for your reply.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.