Repository: Project-MONAI/MONAI

Issue:
Unused `kernel_size` in `ResBlock`
Hi,

I'd like to build a customized SegResNet, where the blocks have different kernel sizes (according to a paper that I found, which handles feature extraction in a similar case as mine with these special kernel sizes).

However, if I construct a network using ResBlocks, I cannot change the kernel sizes, although there is an arg for that:

`resblock = monai.networks.blocks.ResBlock(
            spatial_dims=3, 
            in_channels=8, 
            norm=('GROUP', {'num_groups': 4}), 
            kernel_size=5, 
            act=('RELU', {'inplace': True})
            )
`
Output:

ResBlock(
  (norm1): GroupNorm(4, 8, eps=1e-05, affine=True)
  (norm2): GroupNorm(4, 8, eps=1e-05, affine=True)
  (act): ReLU(inplace=True)
  (conv1): Convolution(
    (conv): Conv3d(8, 8, kernel_size=(3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1), bias=False)
  )
  (conv2): Convolution(
    (conv): Conv3d(8, 8, kernel_size=(3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1), bias=False)
  )
)

Note, that although I passed a kernel_size = 5 arg, they are still size 3. Any hints? Thanks!

_Originally posted by @r00tdotexe in https://github.com/Project-MONAI/tutorials/discussions/1524_
Unused `kernel_size` in `ResBlock`
Hi,

I'd like to build a customized SegResNet, where the blocks have different kernel sizes (according to a paper that I found, which handles feature extraction in a similar case as mine with these special kernel sizes).

However, if I construct a network using ResBlocks, I cannot change the kernel sizes, although there is an arg for that:

`resblock = monai.networks.blocks.ResBlock(
            spatial_dims=3, 
            in_channels=8, 
            norm=('GROUP', {'num_groups': 4}), 
            kernel_size=5, 
            act=('RELU', {'inplace': True})
            )
`
Output:

ResBlock(
  (norm1): GroupNorm(4, 8, eps=1e-05, affine=True)
  (norm2): GroupNorm(4, 8, eps=1e-05, affine=True)
  (act): ReLU(inplace=True)
  (conv1): Convolution(
    (conv): Conv3d(8, 8, kernel_size=(3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1), bias=False)
  )
  (conv2): Convolution(
    (conv): Conv3d(8, 8, kernel_size=(3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1), bias=False)
  )
)

Note, that although I passed a kernel_size = 5 arg, they are still size 3. Any hints? Thanks!

_Originally posted by @r00tdotexe in https://github.com/Project-MONAI/tutorials/discussions/1524_


Discussion:

Resolving patch:
diff --git a/monai/networks/blocks/segresnet_block.py b/monai/networks/blocks/segresnet_block.py
--- a/monai/networks/blocks/segresnet_block.py
+++ b/monai/networks/blocks/segresnet_block.py
@@ -73,8 +73,12 @@ def __init__(
         self.norm1 = get_norm_layer(name=norm, spatial_dims=spatial_dims, channels=in_channels)
         self.norm2 = get_norm_layer(name=norm, spatial_dims=spatial_dims, channels=in_channels)
         self.act = get_act_layer(act)
-        self.conv1 = get_conv_layer(spatial_dims, in_channels=in_channels, out_channels=in_channels)
-        self.conv2 = get_conv_layer(spatial_dims, in_channels=in_channels, out_channels=in_channels)
+        self.conv1 = get_conv_layer(
+            spatial_dims, in_channels=in_channels, out_channels=in_channels, kernel_size=kernel_size
+        )
+        self.conv2 = get_conv_layer(
+            spatial_dims, in_channels=in_channels, out_channels=in_channels, kernel_size=kernel_size
+        )
 
     def forward(self, x):
         identity = x


Test patch:
diff --git a/tests/test_segresnet_block.py b/tests/test_segresnet_block.py
--- a/tests/test_segresnet_block.py
+++ b/tests/test_segresnet_block.py
@@ -23,7 +23,7 @@
 for spatial_dims in range(2, 4):
     for in_channels in range(1, 4):
         for kernel_size in [1, 3]:
-            for norm in ["group", "batch", "instance"]:
+            for norm in [("group", {"num_groups": 1}), "batch", "instance"]:
                 test_case = [
                     {
                         "spatial_dims": spatial_dims,
@@ -34,7 +34,7 @@
                     (2, in_channels, *([16] * spatial_dims)),
                     (2, in_channels, *([16] * spatial_dims)),
                 ]
-            TEST_CASE_RESBLOCK.append(test_case)
+                TEST_CASE_RESBLOCK.append(test_case)
 
 
 class TestResBlock(unittest.TestCase):