Repository navigation
Add dgcnn model - #951
Add dgcnn model#951
Conversation
PierreGtch
left a comment
There was a problem hiding this comment.
Thanks @ShahVandit for your work already! The PR looks good overall. Here are some comments to implement before we merge
Also I launched the tests, let's see if they pass
bruAristimunha
left a comment
There was a problem hiding this comment.
many thanks for the contributions, small details to adjust :)
|
some small details, can you please fill the whats new file, apply pre-commit and then, install your branch here and run the benchmark: Here is some code that is usually used to test if the model is okay. EEGNex is an good baseline method |
|
I ran a quick benchmark on the BNCI2014_001 motor imagery dataset (MOABB) comparing DGCNN against EEGNeX and BrainModule: https://colab.research.google.com/drive/10PSyIqr0PRNJUWDjzkrin9k93vUxhzTl DGCNN underperforms on this benchmark, the original paper used precomputed differential entropy (DE) features on the SEED emotion dataset, not raw EEG time series. |
3fe56a5 to
1338bbf
Compare
|
nice revision! I understand, thinking about it, I think we can generate the features and feed them into the model. We can generate this in many ways, such as preprocessing (in braindecode or moabb) or as a dataloader transformation. Do you have an implementation reference for the feature? I can help you :) |
|
All comments on my side have been addressed, thanks @ShahVandit :) |
|
Hi @bruAristimunha ! Here is my approach:
Would love your guidance on where this fits best - preprocessing or dataloader transform. References: |
|
Hi @bruAristimunha @PierreGtch |
|
Sorry, I had pushed the fix to the wrong branch! I've now applied it to the correct branch and verified all DGCNN tests pass locally. Could you please re-run CI? |
|
hey @ShahVandit, I am looking at the model, and the main problem is that its performance isn't super good. I am testing some things based on your adjusted tutorial. |
|
I tested many, many things today. Looks like it is very sensitive to normalization, and if we adjust the learning parameters, we can improve a little (56% was my max), but still very, very far from the 80% for eegnex. |
|
Thanks for testing! I'm currently running on PhysionetMI (64 channels, closer to SEED's channel count) - the KNN graph should work better with more channels imo. Will update once I have results. Do you think it's worth merging as-is and iterating later, or should we wait for better benchmark results? |
|
@bruAristimunha @PierreGtch |
|
Hi @bruAristimunha |
|
hey @ShahVandit, Many thanks for this PR I am testing, testing, and benchmarking, but it will eventually be merged. If you want to start another PR, I'm happy to review. |
Replace the EdgeConv+kNN point-cloud architecture (Wang et al. 2019)
with the correct Chebyshev spectral graph convolution and learnable
adjacency matrix from the original DGCNN paper for EEG emotion
recognition.
Key changes:
- Learnable adjacency matrix initialized from electrode spatial
positions (chs_info required), with ReLU non-negativity
- Chebyshev polynomial graph filtering (order K) on the normalized
Laplacian L = I - D^{-1/2} A D^{-1/2}
- Single graph conv layer + FC head (matching official TF code)
- chs_info with 3-D electrode positions is now mandatory; the model
raises ValueError if positions are missing
Performance improvement:
- SEED-V within-session: 0.47-0.55 -> 0.97
- BNCI2014_001 cross-session: 0.53 -> 0.63
Official TF code reference: http://aip.seu.edu.cn/songtengfei
(archived in EEG-TAC-official/)
- Fix loc[3:6] → loc[0:3] in extract_channel_locations_from_chs_info (was reading MNE reference vector instead of electrode position) - Add degenerate-position check (return None if all zeros) - Remove DGCNN _extract_positions workaround, use shared utility - Rename graph_dim → n_filters (default=64) for clarity - Use sklearn pairwise_distances and kneighbors_graph - Enrich docstrings with paper math (Eqs. 1, 2, 11-13, Algorithm 1) - Add local architecture figure (DGCNN.gif) - Clean up header comment with archive URL
|
hey @ShahVandit, After a long, long time of revision, I discovered the problem. The initial model implemented was the DGCNN for EEG; it was the implementation for point cloud. Even though they share the same name, they don't actually have the same architecture. |
Co-authored-by: Bru <[email protected]>
Co-authored-by: Bru <[email protected]>
… GNN docs and TorchScript - Add MNE montage inference fallback in _build_initial_adjacency when locs are missing but channel names are available - Add chs_info to required params in model registry (raises ValueError if not provided) - Add activation parameter (type[nn.Module], default=nn.ReLU) - Separate final_layer from classifier Sequential - Add type annotations to all __init__ parameters - Enable GNN category card in docs (remove figclass: unavailable) - Remove DGCNN from TorchScript skip list - Add Channel badge and category to DGCNN - Move import mne to top-level in test_models.py - Fix parameter count in summary.csv (1037385)
- Update DGCNN description to match actual architecture (Chebyshev spectral graph convolution, not EdgeConv/k-NN in feature space) - Change GNN badge from bdg-success to bdg-light to match docs
|
Now it is working, after many hours of studying the paper and finding the original source code. If we want to continue on the graph neural network, it could be interesting to implement the top 5-7 more famous methods. |
There was a problem hiding this comment.
Pull request overview
Adds a new graph-based EEG classification model (DGCNN) to the braindecode.models package, along with docs, model categorization metadata, and a unit test to validate a forward pass.
Changes:
- Added
braindecode.models.DGCNNimplementation and exposed it viabraindecode.models.__init__. - Updated model registry/summary/categorization (including docs + badges) to include a new “Graph Neural Network” category and the DGCNN entry.
- Added a unit test that builds
chs_infofrom an MNE standard montage and checks the model forward pass.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
braindecode/models/dgcnn.py |
New DGCNN model implementation (learnable adjacency + Chebyshev graph conv + MLP head) and model docstring. |
braindecode/models/__init__.py |
Exports DGCNN from the models package. |
braindecode/models/util.py |
Registers DGCNN mandatory params; adjusts channel-location extraction behavior. |
braindecode/models/summary.csv |
Adds DGCNN to the model summary table with categories/metadata. |
test/unit_tests/models/test_models.py |
Adds a dummy forward-pass test for DGCNN using MNE montage-based chs_info. |
test/unit_tests/models/test_model_categorization.py |
Adds “Graph Neural Network” as a known categorization badge. |
docs/models/categorization/gnn.rst |
Updates GNN category page to include DGCNN. |
docs/models/models_categorization.rst |
Minor doc tweak for GNN models diagram markup. |
docs/whats_new.rst |
Adds a release note entry and author link for the DGCNN addition. |
docs/_static/model/DGCNN.gif |
Adds model architecture image asset. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix the DGCNN docstring figure path from ../docs/_static/ to ../_static/ so it resolves correctly from the autosummary-generated pages in docs/generated/. Set DOCSTRING_INHERITANCE_ENABLE=1 in docs/conf.py before any imports so NumpyDocstringInheritanceInitMeta actually merges parent parameters (n_outputs, n_chans, etc.) into child model docstrings.
Replace short math-style names (A, d, W, I, k) with descriptive names following braindecode conventions: electrode_positions, adjacency, degree, gaussian_weights, cheb_components, etc. Also expand "FC" to "fully connected" in docstrings.
Add Architectural Overview, Macro Components, Graph Convolution Details, and Additional Comments sections following the same structure used in EEGNet and ATCNet. Include direct quotes from the original paper and describe how spatial, spectral, and temporal information is encoded.
Summary
DGCNN(Dynamic Graph Convolutional Neural Network) adapted for EEG classificationReference
Song, T., Zheng, W., Song, P., & Cui, Z. (2018). EEG emotion recognition using dynamical
graph convolutional neural networks. IEEE Transactions on Affective Computing, 11(3), 532–541.
https://doi.org/10.1109/TAFFC.2018.2817622