Skip to content

Refactor shared EMG model support components - #1145

Merged
bruAristimunha merged 4 commits into
masterfrom
refactor/emg-pose-shared-components
Aug 30, 2026
Merged

bruAristimunha merged 4 commits into
masterfrom
refactor/emg-pose-shared-components

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Extract the reusable support pieces needed by the sEMG pose baselines into a focused prerequisite PR:

  • centralize output-head replacement in EEGModuleMixin
  • expose one scriptable TDS encoder reused by EMG2Qwerty and VEMG2Pose
  • migrate Dance and EMG2Qwerty to the shared implementations
  • add focused module tests

This is the support layer for #1132. Keeping it separate lets #1132 contain the three pose models and their model-specific integration only.

Verification

  • python -m pytest test/unit_tests/models/test_modules.py -q (206 passed)
  • python -m pytest test/unit_tests/models/test_models.py -k emg2qwerty -q (8 passed)
  • python -m pytest test/unit_tests/models/test_models.py -k dance -q (2 passed)
  • pre-commit on all changed files

Copilot AI lite review requested due to automatic review settings August 30, 2026 11:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors and centralizes shared sEMG baseline support components so existing models (Dance, EMG2Qwerty) and upcoming pose baselines can reuse common head-reset logic, TDS encoder blocks, and SMU activation.

Changes:

  • Introduces reusable TDS encoder building blocks (TDSConv2dBlock, TDSFullyConnectedBlock, TDSConvEncoder) and adds unit tests for layout equivalence + TorchScript.
  • Adds SmoothMaximumUnit activation and exports new shared components via braindecode.modules.
  • Centralizes n_outputs bookkeeping via EEGModuleMixin._set_n_outputs and updates Dance/EMG2Qwerty to use it.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/unit_tests/models/test_modules.py Adds focused tests for TDS blocks (layout equivalence + TorchScript).
braindecode/modules/blocks.py Adds shared TDS convolution/FC blocks and encoder implementation.
braindecode/modules/activation.py Adds SmoothMaximumUnit activation.
braindecode/modules/init.py Exposes new activation and TDS blocks as public module exports.
braindecode/models/emg2qwerty.py Migrates to shared TDS encoder and centralizes head reset bookkeeping.
braindecode/models/dance.py Migrates head reset bookkeeping to _set_n_outputs.
braindecode/models/base.py Adds _set_n_outputs helper to keep configs and n_outputs synchronized.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +457 to 461
self._set_n_outputs(n_outputs)
old_head = self.final_layer
self.final_layer = nn.Linear(old_head.in_features, n_outputs).to(
device=old_head.weight.device, dtype=old_head.weight.dtype
)
Comment on lines 352 to 360
@@ -359,10 +358,3 @@ def reset_head(self, n_outputs: int) -> None:
self.decoder.class_head = nn.Linear(ch.in_features, n_outputs).to(
device=ch.weight.device, dtype=ch.weight.dtype
)
Copilot AI review requested due to automatic review settings August 30, 2026 11:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 621c874a73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread braindecode/modules/blocks.py Outdated
)


class TDSConv2dBlock(nn.Module):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the TDS blocks' noncommercial license

These classes are extracted from emg2qwerty.py, whose implementation is explicitly inherited under CC BY-NC-SA 4.0, but placing them in modules/blocks.py makes them subject to the repository's default BSD-3 declaration: NOTICE.txt:7-33 lists only models/emg2qwerty.py as the relevant license exception. Consequently, users importing the newly public TDS blocks are told they may use them commercially and without ShareAlike obligations. Keep the extracted implementation in a separately attributed CC BY-NC-SA file and add it to the notice, or otherwise preserve the inherited licensing metadata.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread docs/whats_new.rst Outdated
Comment on lines +31 to +35
- Add reusable temporal-distributed separable convolution blocks and the
smooth maximum unit activation to :mod:`braindecode.modules`, and centralize
output-head replacement for models using
:class:`braindecode.models.base.EEGModuleMixin` (:gh:`1145` by `Bruno
Aristimunha`_)
Copilot AI review requested due to automatic review settings August 30, 2026 11:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread docs/whats_new.rst Outdated
Comment on lines +31 to +35
- Add reusable temporal-distributed separable convolution blocks and the
smooth maximum unit activation to :mod:`braindecode.modules`, and centralize
output-head replacement for models using
:class:`braindecode.models.base.EEGModuleMixin` (:gh:`1145` by `Bruno
Aristimunha`_)
Copilot AI review requested due to automatic review settings August 30, 2026 11:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (1)

docs/whats_new.rst:31

  • The release note calls this a "temporal-distributed separable convolution" encoder, but the implementation and naming (TDS = time-depth-separable) indicate it should be described as a time-depth-separable convolution encoder to avoid confusing terminology.
- Add a reusable temporal-distributed separable convolution encoder to

@bruAristimunha
bruAristimunha merged commit ba79a8b into master Aug 30, 2026
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants