ravikiran-mane / FBCNet

FBCNet: An Efficient Multi-view Convolutional Neural Network for Brain-Computer Interface
MIT License
120 stars 32 forks source link

Array index is out of bound io matToPython.py #3

Open jungla88 opened 2 years ago

jungla88 commented 2 years ago

I think there are some confusion with loop indices in this file:

  for i, d in enumerate(data):
      sub = int(d['fileName'][-7:-4]) # subject of the data
      sub = str(sub).zfill(3)

      if d['fileName'][1] == 'e':
          session = 1;
      elif d['fileName'][1] == '-':
          session = int(d['fileName'][2:4])
      else:
          session =0;

      if len(d['data']['labels']) ==1:
          d['data']['labels'] = np.transpose(d['data']['labels'])

      for j, label in enumerate(d['data']['labels']):
          lab = label[0]
          # get the data
          if isFiltered:
              x = {'id': id, 'data': d['data']['eeg'][j,:,:,:], 'label': lab}
          else:
              x = {'id': id, 'data': d['data']['eeg'][j,:,:], 'label': lab}

Index i in first loop is never used (check with IDE or any linter), whilst j goes out of bound for d[data][eeg] (I checked only the first branch). Shapes for BCI2a dataset is the following:

d['data']['eeg'].shape
(1, 22, 1000)
ravikiran-mane commented 2 years ago

@jungla88 The loop index was not used because all the operations were performed on 'd' and it can be safely removed. For the 'Array index is out of bound' error, can you share the entire error stack? Also, did you download the BCI dataset from physionet?

jungla88 commented 2 years ago

I am not sure about the dataset, but it should come from the original website of BCI competition. Here the stack:

  File "/home/lbaldini/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/home/lbaldini/Projects/FBCNet/codes/classify/ho.py", line 373, in <module>
    ho(datasetId, network, nGPU, subTorun)
  File "/home/lbaldini/Projects/FBCNet/codes/classify/ho.py", line 194, in ho
    fetchData(os.path.dirname(config['inDataPath']), datasetId) # Make sure that all the required data is present!
  File "/home/lbaldini/Projects/FBCNet/codes/centralRepo/saveData.py", line 622, in fetchData
    matToPython(
  File "/home/lbaldini/Projects/FBCNet/codes/centralRepo/saveData.py", line 385, in matToPython
    x = {"id": id, "data": d["data"]["eeg"][j, :, :], "label": lab}
IndexError: index 1 is out of bounds for axis 0 with size 1

My temporary workaround is to set j=0, returning a structure with shape (#channels, #time). This make all works and EEG Dataset with FBCNet do not raise any error about data.

xinyiccc commented 2 years ago

I had the same problem. I think the issue lies in the shape of mat type data. We cannot collect all 288 experimental data when the hyperparameter event Code sets [2].

t170815518 commented 2 years ago

Same situation here. The shape of d['data']['eeg'] is (1, 22, 1000).

t170815518 commented 2 years ago

I had the same problem. I think the issue lies in the shape of mat type data. We cannot collect all 288 experimental data when the hyperparameter event Code sets [2].

I agree with @xinyiccc.

After analyzing the codes at saveData.py from line 62 like:

    events = [event for event in gdf_events if event[1] in eventCode]

From the count distribution of gdf_events, e.g. Counter({6: 288, 7: 72, 8: 72, 9: 72, 10: 72, 1: 18, 5: 9, 3: 1, 4: 1, 2: 1}) I infer that eventCode = [6] instead of [2], which would cause dimension error as all of us faced.

However, changing the eventCode still raises error for s004.mat... For other subjects, it seems fine

xinyiccc commented 2 years ago

I have the same solution as you, but I also encountered this problem @ t170815518. Fortunately, I found the cause of the problem. The reason is that the experimental results of the fourth subject are incomplete, which leads to the fact that its four classification labels are not [7,8,9,10], but [5,6,7,8]. After I solve this problem, the code can run correctly. I hope it can also help you.

t170815518 commented 2 years ago

Thank you for this! @xinyiccc

ravikiran-mane commented 1 year ago

@jungla88 @t170815518 @xinyiccc Thank you for helping debug this issue. I have patched the saveData.py file. Do download the latest version and share if it solves your issue.