Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restormer Implementation #8312

Merged
merged 75 commits into from
Mar 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
3db93ce
Add new pixel unshuffle for SubPixelDownsample class
phisanti Jan 15, 2025
9693e04
Add unit test for pixelunshuffle
phisanti Jan 15, 2025
a89f299
Add DownSample Modes
phisanti Jan 15, 2025
450691f
expand pixelunshuffle for 3D
phisanti Jan 16, 2025
d0920d8
increase testing for pixelunshuffle
phisanti Jan 16, 2025
1a48d4d
expand pixelunshuffle for 3D images
phisanti Jan 16, 2025
fe47807
add SubpixelDownsample and tests
phisanti Jan 16, 2025
86155cd
Add DownSample Class
phisanti Jan 16, 2025
137a7f2
Add tests for Downsample
phisanti Jan 16, 2025
fb17baf
add exports to __init__
phisanti Jan 16, 2025
5ff0baa
Include test to compare with Conv + unshuffle from original restormer
phisanti Jan 16, 2025
2566db1
remove relative imports
phisanti Jan 16, 2025
ac4047b
Create restormer with Downsampler/Upsampler using monai implementation
phisanti Jan 17, 2025
2b74270
Add channel attention block
phisanti Jan 17, 2025
9b74533
add assembled restormer with MONAI convs for 3D
phisanti Jan 17, 2025
1ab34f6
restormer adapted for 2D/3D
phisanti Jan 20, 2025
4f4c62c
Add unit test for CABlock and the FeedForward layers
phisanti Jan 20, 2025
068688f
remove relative imports
phisanti Jan 20, 2025
e2e1070
rename restormer
phisanti Jan 20, 2025
35c7ee4
add unit test restormer
phisanti Jan 20, 2025
d8cb6c1
Update documentation and imports for CABlock and FeedForward; add Dow…
phisanti Jan 23, 2025
6d96816
Add licence to pixel_unshuffle test
phisanti Jan 23, 2025
8a688fb
Refactor imports and clean up whitespace in utils and test files and …
phisanti Jan 23, 2025
acb818d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 23, 2025
6352ba9
DCO Remediation Commit for tisalon <[email protected]>
phisanti Jan 23, 2025
c7b1af4
add optional_import to downsample block test
phisanti Jan 24, 2025
8faa5da
rename args and fix imports
phisanti Feb 7, 2025
be89958
Using LocalStore in Zarr v3 (#8299)
KumoLiu Jan 15, 2025
c17938b
8267 fix normalize intensity (#8286)
advcu987 Jan 20, 2025
64613a7
Fix bundle download error from ngc source (#8307)
KumoLiu Jan 21, 2025
5643d4a
Fix deprecated usage in zarr (#8313)
KumoLiu Jan 24, 2025
595674a
update pydicom reader to enable gpu load (#8283)
yiheng-wang-nv Jan 27, 2025
c775393
Zarr compression tests only with versions before 3.0 (#8319)
ericspod Feb 3, 2025
61efefb
Sync dev branch with upstream MONAI changes
phisanti Feb 7, 2025
091887b
Clarify input tensor shape in pixelshuffle and pixelunshuffle functio…
phisanti Feb 7, 2025
5d162d0
Refactor downsample mode checks to use enum values for clarity
phisanti Feb 7, 2025
f520e99
fix optiona import
phisanti Feb 7, 2025
39d1edf
Refactor layer normalization parameters for consistency and clarity i…
phisanti Feb 7, 2025
5b3d4e1
Enhance documentation for MDTATransformerBlock, OverlapPatchEmbed an…
phisanti Feb 7, 2025
1683b14
run ./runtests.sh --autofix to check formatting
phisanti Feb 7, 2025
232be1c
Refactor OverlapPatchEmbed to inherit from Convolution and streamline…
phisanti Feb 7, 2025
d1df8e6
Enhance documentation for FeedForward and CABlock classes, adding arg…
phisanti Feb 7, 2025
78ce56b
code formatting
phisanti Feb 7, 2025
64b203d
Update args naming in unit restormer test for consistency with sugges…
phisanti Feb 7, 2025
ce15886
Fix optional import
phisanti Feb 7, 2025
30fad17
require einops for all tests
phisanti Feb 7, 2025
1079d8c
require einops also for test_restormer
phisanti Feb 7, 2025
b2b3ddf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 7, 2025
174e968
remove relative impots
phisanti Feb 7, 2025
e15a815
fix capitalisation in DownSample documentation networks.rts
phisanti Feb 7, 2025
d53d97d
fix capitalisation in SubpixelDownsample documentation
phisanti Feb 7, 2025
cae7d96
formatting
phisanti Feb 7, 2025
a0afee5
update docstring to mention 2D and 3D cases
phisanti Feb 7, 2025
529e90b
Update type annotations and doctring
phisanti Feb 9, 2025
c109029
remove problematic unit test
phisanti Feb 9, 2025
19c30f7
remove problematic unit test
phisanti Feb 9, 2025
0b0e4df
Merge remote-tracking branch 'upstream/dev' into dev
phisanti Mar 1, 2025
55da640
relocate test in the correct place
phisanti Mar 1, 2025
3c2dbc6
Add DownSampleBlock missing tests, Signed-off-by: Santiago Cano-Muniz…
phisanti Mar 1, 2025
da0a186
Merge branch 'dev' into dev
phisanti Mar 8, 2025
f17e06e
Re-order skipUnless in test_restormer.py, Signed-off-by: Cano-Muniz, …
phisanti Mar 8, 2025
4573ec9
Clarify comments for RESTORMER_CONFIGS in test_restormer.py,
phisanti Mar 8, 2025
8c564aa
Remove duplicated test_CABlock.py as part of codebase cleanup. In add…
phisanti Mar 8, 2025
3e013fe
Refactor test cases in test_restormer.py to conditionally define clas…
phisanti Mar 8, 2025
06be2ef
formatting error in line 237. Solved by updating black from 24.10.0 t…
phisanti Mar 8, 2025
c02d794
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 8, 2025
7f46ac5
Remove duplicated tests and place the order of the decorators (skipUn…
phisanti Mar 11, 2025
baf7541
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 11, 2025
aeebc89
Remove debug print statement for einops availability in test_restorme…
phisanti Mar 11, 2025
7342b84
Address mypy suggestions for type annotations in cablock.py, downsamp…
phisanti Mar 11, 2025
c608375
Merge branch 'dev' into dev
ericspod Mar 13, 2025
395ce89
Merge branch 'dev' into dev
KumoLiu Mar 14, 2025
22890d6
Merge branch 'dev' into dev
KumoLiu Mar 20, 2025
5eaf79f
Merge branch 'dev' into dev
ericspod Mar 22, 2025
f2f8e34
Merge branch 'dev' into dev
ericspod Mar 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add new pixel unshuffle for SubPixelDownsample class
phisanti committed Jan 15, 2025
commit 3db93ce8e151f298609061a3e0589cf485baa8aa
31 changes: 31 additions & 0 deletions monai/networks/utils.py
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@
"normal_init",
"icnr_init",
"pixelshuffle",
"pixelunshuffle",
"eval_mode",
"train_mode",
"get_state_dict",
@@ -411,6 +412,36 @@ def pixelshuffle(x: torch.Tensor, spatial_dims: int, scale_factor: int) -> torch
return x


def pixelunshuffle(x: torch.Tensor, spatial_dims: int, scale_factor: int) -> torch.Tensor:
"""
Apply pixel unshuffle to the tensor `x` with spatial dimensions `spatial_dims` and scaling factor `scale_factor`.
Inverse operation of pixelshuffle.
Args:
x: Input tensor
spatial_dims: number of spatial dimensions, typically 2 or 3 for 2D or 3D
scale_factor: factor to reduce the spatial dimensions by, must be >=1
Returns:
Unshuffled version of `x`.
"""
dim, factor = spatial_dims, scale_factor
input_size = list(x.size())
batch_size, channels = input_size[:2]

output_channels = channels * (factor**dim)
output_spatial = [d // factor for d in input_size[2:]]
output_size = [batch_size, output_channels] + output_spatial

x = x.reshape([batch_size, channels] + [factor] * dim + output_spatial)

indices = list(range(2, 2 + 2 * dim))
indices = indices[dim:] + indices[:dim]
permute_indices = [0, 1] + indices

x = x.permute(permute_indices).reshape(output_size)
return x

@contextmanager
def eval_mode(*nets: nn.Module):
"""