Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jungla88 opened this issue Nov 7, 2022 · 8 comments
Open

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

jungla88 opened this issue Nov 7, 2022 · 8 comments

Comments

@jungla88
Copy link

jungla88 commented Nov 7, 2022

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
Copy link
Owner

@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
Copy link
Author

jungla88 commented Nov 8, 2022

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.

@jungla88 jungla88 closed this as completed Nov 8, 2022
@jungla88 jungla88 reopened this Nov 8, 2022
@xinyiccc
Copy link

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
Copy link

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

@t170815518
Copy link

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
Copy link

xinyiccc commented Dec 2, 2022

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
Copy link

Thank you for this! @xinyiccc

@ravikiran-mane
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants