gifale95 / eeg_encoding

Use DNNs to build encoding models of EEG visual responses.
https://www.alegifford.com/projects/eeg_dataset/
MIT License
70 stars 12 forks source link

preprocessing.py --n_ses=1 errors out on broadcasting shape mismatch #5

Closed 3x10e8 closed 1 month ago

3x10e8 commented 1 month ago

Dear developers, Thank you so much for making your code available!

I was going through the steps to extract the raw data into epochs, and tried reducing the n_ses parameter value from 4 (default) to 1 to only get a subset of the data:

https://github.com/gifale95/eeg_encoding/blob/0e048f7c6ae3aec0495b288662389fd51b9b1eaa/02_eeg_preprocessing/preprocessing.py#L34

But this results in a shape error for the line merged_train[i] = ordered_data in the context:

https://github.com/gifale95/eeg_encoding/blob/0e048f7c6ae3aec0495b288662389fd51b9b1eaa/02_eeg_preprocessing/preprocessing_utils.py#L254-L262

The error is: ValueError: could not broadcast input array from shape (2,17,100) into shape (4,17,100)

I can try to fix it later, I just wanted to log it here in case anyone else sees this on trying to reduce n_ses. The test epochs get extracted correctly, only the training epochs seem to be affected.

gifale95 commented 1 month ago

Hi Abhinav, thanks for pointing this out!

The preprocessing script you mentioned, along with the following scripts to reproduce the paper results, were intentionally written assuming EEG data from 4 sessions.

This being said, if you wish to preprocess the data from only 1 session, you can replace the code you printed above with:

    # Data matrix of shape:
    # Image conditions × EEG repetitions × EEG channels × EEG time points
    if args.n_ses == 1:
        reps = white_data.shape[1]
    else:
        reps = white_data.shape[1] * 2
    merged_train = np.zeros((len(np.unique(img_cond)), reps,
        white_data.shape[2], white_data.shape[3]))
    for i in range(len(np.unique(img_cond))):
        # Find the indices of the selected category
        idx = np.where(img_cond == i+1)[0]
        for r in range(len(idx)):
            if r == 0:
                ordered_data = white_data[idx[r]]
            else:
                ordered_data = np.append(ordered_data, white_data[idx[r]], 0)
        merged_train[i] = ordered_data

However, note that the remaining code of the repository assumes EEG data from 4 sessions, and therefore might not work on data from only 1 session.

Hope this helps! Ale