Repository navigation
FIX EEGRegressor: compare squeezed predictions with their own target - #1833
Merged
bruAristimunha merged 3 commits intoNov 29, 2026
Merged
bruAristimunha merged 3 commits into
bruAristimunha merged 3 commits into
Conversation
EEGRegressor.fit reshapes a 1-D y to (n, 1). When the module returns (batch,), MSELoss broadcast the pair to (batch, batch) and compared every prediction with every target. get_loss now squeezes such a target, the mirror of the (batch, 1) prediction and (batch,) target case of braindecode#1197.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1833 +/- ##
==========================================
- Coverage 93.98% 93.97% -0.02%
==========================================
Files 192 192
Lines 26379 26377 -2
==========================================
- Hits 24793 24787 -6
- Misses 1586 1590 +4 🚀 New features to boost your workflow:
|
# Conflicts: # docs/whats_new.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EEGRegressor.fitreshapes a 1-Dyto(n, 1). When the module returns(batch,), such as a custom head ending insqueeze(-1),MSELossbroadcasts the pair to(batch, batch)and compares every prediction with every target. This is the mirror of #1180: #1197 handles a(batch, 1)prediction with a(batch,)target, and #1198 handlesCroppedLoss.Changes
EEGRegressor.get_losssqueezes a(batch, 1)target when the prediction is 1-D.test_eegregressor_loss_is_per_trial_mse_for_each_shape_pair: hard-coded loss for the four(batch,)/(batch, 1)pairs.docs/whats_new.rst: entry under Bug fixes.Testing
Windows, Python 3.12.10, torch 2.15.0+cpu. AGENTS.md sections 5, 6, 7, 10 and 11 apply.
pytest test/unit_tests/test_eegneuralnet.py -n 2 -q -rfEs: 108 passed, 0 skipped (master: 104 passed).Mutation check: without the new branch, case
[pred_shape0-target_shape1]fails (22.625 instead of 7.5). Withouty_pred.ndim == 1ory_true.ndim == 2, another case of the same test fails. The twoisinstancechecks repeat those of the existing branch and have no test; a probe raisesAttributeErrorwithout each.Parity with
master(script below,OMP_NUM_THREADS=1; losses and gradients in float64):torch.equalin 99/99 cases for the other shapes and paths, one-trial batches and cropped mode included. For(batch,)with(batch, 1), 11/14 change; the 3 others are one-trial batches.The 104 registered models, built with
n_outputs=1and run on 2 trials: none returns a 1-D output.test/unit_tests/training,test_util.py,augmentation/test_base.py,models/test_emg_pose_baselines.py,test_docstring_parameters.py,test_dependencies.py,test_no_error_catching.py,test_lazy_imports.pyand three acceptance files: 541 passed, 86 skipped, same onmaster. Skips: 70 models withoutch_mask, 1 fNIRS montage, 1 CUDA, 10--run-network, 4 classes that forward**kwargs.The two ECoG examples (
plot_bcic_iv_4_ecog_trial.py,plot_bcic_iv_4_ecog_cropped.py) give the same loss values as onmasterin all 48 and 144get_losscalls (digest of the values,OMP_NUM_THREADS=1). They andplot_regression.pyrun without a broadcasting warning.Not run locally: the full suite (
ci_plan.pyasks for it, sinceregressor.pyis a global trigger) and the full documentation build (the changelog page and theget_lossdocstring render with Sphinx 8.2.3).New or changed behavior is covered by relevant regression tests (or N/A with reason)
Style checks recorded, e.g.
pre-commit run --files <changed files>docs/whats_new.rstupdated (at most 3 lines), or theno changeloglabel, which a maintainer adds, for changes to code that is not released yet (the changelog CI check requires one of the two)Notes for reviewers
(batch,)with a(batch, 1)target train differently than in 2.1 (regressor.pyis unchanged sincev2.1.0).(batch,)target.t.squeeze(-1),t.flatten()andp.view_as(t)still give the per-trial loss.t.squeeze(1)andt[:, 0]raiseIndexError.mse(p.unsqueeze(1), t)becomes the broadcast loss, with torch's warning.BCEWithLogitsLoss, which raisedValueError, now works.(batch, 1)instead would give the broadcast loss for all of these exceptview_asandBCEWithLogitsLoss. Fix EEGRegressor loss broadcasting for one target per trial #1197 has the mirror effect on a criterion that callst.unsqueeze(1).Parity script (run with
saveon master,compareon this branch)