You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 21ab521
Browse filesBrowse the repository at this point in the historyBrowse files
Add spatial and channel-spatial SE layers and use them in Quicknat (#9278)
Fixes#9276.
### Description
`Quicknat` imported `SpatialSELayer` and `ChannelSpatialSELayer` from
`squeeze_and_excitation`, which is not on PyPI. The SSE and CSSE options
could not be used, and the test class that covers them was always
skipped.
- Add `SpatialSELayer` (sSE) and `ChannelSpatialSELayer` (scSE) to
`monai/networks/blocks/squeeze_and_excitation.py`, following Roy et al.,
"Concurrent Spatial and Channel Squeeze & Excitation in Fully
Convolutional Networks" (https://arxiv.org/abs/1803.02579). Both support
1D, 2D and 3D. sSE is a 1x1 convolution to one channel followed by a
sigmoid. scSE takes the element-wise maximum of `ChannelSELayer` and
`SpatialSELayer`, as in the package Quicknat was written against.
- Export both from `monai.networks.blocks` and add them to
`docs/source/networks.rst`.
- `Quicknat.get_selayer` uses the new layers, and the `optional_import`
is removed.
- `tests/networks/nets/test_quicknat.py`: the `skipUnless` is removed,
so the CSE, SSE and CSSE shape tests now run.
- `tests/networks/blocks/test_se_blocks.py`: shape, value and
TorchScript tests for both new layers.
One thing came up while doing this. With the skip removed,
`TestQuicknat.test_script` fails because `Quicknat` was never
TorchScript compatible: `ConvConcatDenseBlock.forward` uses `continue`
inside a loop over child modules, and `Encoder`/`Decoder` call
`super().forward()`. That needs a refactor of those blocks, so I've kept
it out of this PR and marked the test with `unittest.skip` and the
reason. I'm happy to open a separate issue for it, or follow up with a
PR.
Note on checkpoints: Quicknat models saved with `se_block="SSE"` or
`"CSSE"` against the external package use different `state_dict` keys
(`cSE`/`sSE`, and `fc1`/`fc2` inside the channel branch) and will not
load strictly. That package was never on PyPI or a MONAI dependency, so
this only affects source installs of it. `se_block="CSE"` and `None` are
unchanged.
### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [x] New tests added to cover the changes.
- [x] In-line docstrings updated.
- [x] Documentation updated.
Tested locally (CPU, PyTorch 2.15.0): `python -m unittest
tests.networks.nets.test_quicknat tests.networks.blocks.test_se_blocks
tests.networks.blocks.test_se_block` gives 48 tests OK, 1 skipped
(`test_script` above). `ruff check` is clean.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Signed-off-by: Bakary Gibba <162592884+BakaryGibba@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,11 @@ All notable changes to MONAI are documented in this file.
4
4
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
5
5
6
6
## [Unreleased]
7
+
### Added
8
+
*`SpatialSELayer` and `ChannelSpatialSELayer` in `monai.networks.blocks`: spatial (sSE) and concurrent spatial and channel (scSE) squeeze-and-excitation layers for 1D, 2D and 3D inputs, based on ["Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks"](https://arxiv.org/abs/1803.02579). (#9278)
9
+
### Fixed
10
+
*`Quicknat` no longer depends on the unpublished `squeeze_and_excitation` package for `se_block="SSE"` and `"CSSE"`. Checkpoints saved with that package for these two options use different `state_dict` keys and will not load strictly. (#9276)
11
+
*`ChannelSELayer` raises `ValueError` instead of `ZeroDivisionError` when `r=0`.
se_block: Squeeze and Excite block type to include. Use ``None`` or ``"None"`` to disable it; valid enabled values are ``"CSE"``, ``"SSE"``, and ``"CSSE"``.
346
+
``"SSE"`` and ``"CSSE"`` now use :py:class:`monai.networks.blocks.SpatialSELayer` and
347
+
:py:class:`monai.networks.blocks.ChannelSpatialSELayer` instead of the external
348
+
``squeeze_and_excitation`` package, so weights saved with that package for these two options
349
+
have different ``state_dict`` keys and will not load with ``strict=True``.
350
350
drop_out: dropout ratio. Defaults to no dropout.
351
351
act: activation type and arguments. Defaults to PReLU.
352
352
norm: feature normalization type and arguments. Defaults to instance norm.
0 commit comments