From c7feb19c189f08efde5151441afcf8b50799c411 Mon Sep 17 00:00:00 2001 From: Yiheng Wang Date: Tue, 24 Aug 2021 12:44:12 +0800 Subject: [PATCH 1/3] update dynunet block norm layers Signed-off-by: Yiheng Wang --- monai/networks/blocks/dynunet_block.py | 16 +++++++++------- monai/networks/nets/dynunet.py | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/monai/networks/blocks/dynunet_block.py b/monai/networks/blocks/dynunet_block.py index bb654d841c..caa292b21f 100644 --- a/monai/networks/blocks/dynunet_block.py +++ b/monai/networks/blocks/dynunet_block.py @@ -32,8 +32,8 @@ class UnetResBlock(nn.Module): out_channels: number of output channels. kernel_size: convolution kernel size. stride: convolution stride. - norm_name: feature normalization type and arguments. - + norm_name: feature normalization type and arguments. Defaults to ``("INSTANCE", {"affine": True})``, which is + used in the referred papers. """ def __init__( @@ -43,7 +43,7 @@ def __init__( out_channels: int, kernel_size: Union[Sequence[int], int], stride: Union[Sequence[int], int], - norm_name: Union[Tuple, str], + norm_name: Union[Tuple, str] = ("INSTANCE", {"affine": True}), ): super(UnetResBlock, self).__init__() self.conv1 = get_conv_layer( @@ -106,7 +106,8 @@ class UnetBasicBlock(nn.Module): out_channels: number of output channels. kernel_size: convolution kernel size. stride: convolution stride. - norm_name: feature normalization type and arguments. + norm_name: feature normalization type and arguments. Defaults to ``("INSTANCE", {"affine": True})``, which is + used in the referred papers. """ @@ -117,7 +118,7 @@ def __init__( out_channels: int, kernel_size: Union[Sequence[int], int], stride: Union[Sequence[int], int], - norm_name: Union[Tuple, str], + norm_name: Union[Tuple, str] = ("INSTANCE", {"affine": True}), ): super(UnetBasicBlock, self).__init__() self.conv1 = get_conv_layer( @@ -163,7 +164,8 @@ class UnetUpBlock(nn.Module): kernel_size: convolution kernel size. stride: convolution stride. upsample_kernel_size: convolution kernel size for transposed convolution layers. - norm_name: feature normalization type and arguments. + norm_name: feature normalization type and arguments. Defaults to ``("INSTANCE", {"affine": True})``, which is + used in the referred papers. """ @@ -175,7 +177,7 @@ def __init__( kernel_size: Union[Sequence[int], int], stride: Union[Sequence[int], int], upsample_kernel_size: Union[Sequence[int], int], - norm_name: Union[Tuple, str], + norm_name: Union[Tuple, str] = ("INSTANCE", {"affine": True}), ): super(UnetUpBlock, self).__init__() upsample_stride = upsample_kernel_size diff --git a/monai/networks/nets/dynunet.py b/monai/networks/nets/dynunet.py index 4af70b22c7..e9bf03a64c 100644 --- a/monai/networks/nets/dynunet.py +++ b/monai/networks/nets/dynunet.py @@ -86,7 +86,7 @@ class DynUNet(nn.Module): strides: convolution strides for each blocks. upsample_kernel_size: convolution kernel size for transposed convolution layers. The values should equal to strides[1:]. - norm_name: feature normalization type and arguments. Defaults to ``INSTANCE``. + norm_name: feature normalization type and arguments. Defaults to ``("INSTANCE", {"affine": True})``. deep_supervision: whether to add deep supervision head before output. Defaults to ``False``. If ``True``, in training mode, the forward function will output not only the last feature map, but also the previous feature maps that come from the intermediate up sample layers. From 6bae73839d5d5f7aa41b4782d50732c3c24502de Mon Sep 17 00:00:00 2001 From: Yiheng Wang Date: Tue, 24 Aug 2021 13:01:42 +0800 Subject: [PATCH 2/3] add more notifications in docstrings Signed-off-by: Yiheng Wang --- monai/networks/blocks/dynunet_block.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/monai/networks/blocks/dynunet_block.py b/monai/networks/blocks/dynunet_block.py index caa292b21f..b803d7fea1 100644 --- a/monai/networks/blocks/dynunet_block.py +++ b/monai/networks/blocks/dynunet_block.py @@ -32,8 +32,10 @@ class UnetResBlock(nn.Module): out_channels: number of output channels. kernel_size: convolution kernel size. stride: convolution stride. - norm_name: feature normalization type and arguments. Defaults to ``("INSTANCE", {"affine": True})``, which is - used in the referred papers. + norm_name: feature normalization type and arguments. If you need to use `"group"` or `"instance"` and want to + maintain the consistency with previous version v0.5.3, please set `affine=True`. For example: + `norm_name=("instance", {"affine": True})`. + """ def __init__( @@ -43,7 +45,7 @@ def __init__( out_channels: int, kernel_size: Union[Sequence[int], int], stride: Union[Sequence[int], int], - norm_name: Union[Tuple, str] = ("INSTANCE", {"affine": True}), + norm_name: Union[Tuple, str], ): super(UnetResBlock, self).__init__() self.conv1 = get_conv_layer( @@ -106,8 +108,9 @@ class UnetBasicBlock(nn.Module): out_channels: number of output channels. kernel_size: convolution kernel size. stride: convolution stride. - norm_name: feature normalization type and arguments. Defaults to ``("INSTANCE", {"affine": True})``, which is - used in the referred papers. + norm_name: feature normalization type and arguments. If you need to use `"group"` or `"instance"` and want to + maintain the consistency with previous version v0.5.3, please set `affine=True`. For example: + `norm_name=("instance", {"affine": True})`. """ @@ -118,7 +121,7 @@ def __init__( out_channels: int, kernel_size: Union[Sequence[int], int], stride: Union[Sequence[int], int], - norm_name: Union[Tuple, str] = ("INSTANCE", {"affine": True}), + norm_name: Union[Tuple, str], ): super(UnetBasicBlock, self).__init__() self.conv1 = get_conv_layer( @@ -164,8 +167,9 @@ class UnetUpBlock(nn.Module): kernel_size: convolution kernel size. stride: convolution stride. upsample_kernel_size: convolution kernel size for transposed convolution layers. - norm_name: feature normalization type and arguments. Defaults to ``("INSTANCE", {"affine": True})``, which is - used in the referred papers. + norm_name: feature normalization type and arguments. If you need to use `"group"` or `"instance"` and want to + maintain the consistency with previous version v0.5.3, please set `affine=True`. For example: + `norm_name=("instance", {"affine": True})`. """ @@ -177,7 +181,7 @@ def __init__( kernel_size: Union[Sequence[int], int], stride: Union[Sequence[int], int], upsample_kernel_size: Union[Sequence[int], int], - norm_name: Union[Tuple, str] = ("INSTANCE", {"affine": True}), + norm_name: Union[Tuple, str], ): super(UnetUpBlock, self).__init__() upsample_stride = upsample_kernel_size @@ -215,7 +219,8 @@ def __init__(self, spatial_dims: int, in_channels: int, out_channels: int): ) def forward(self, inp): - return self.conv(inp) + out = self.conv(inp) + return out def get_conv_layer( From 5f8a8823e3daa7479638f0af6cac1f4ff1b060da Mon Sep 17 00:00:00 2001 From: Yiheng Wang Date: Tue, 24 Aug 2021 13:05:59 +0800 Subject: [PATCH 3/3] remove unexpected changes Signed-off-by: Yiheng Wang --- monai/networks/blocks/dynunet_block.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/monai/networks/blocks/dynunet_block.py b/monai/networks/blocks/dynunet_block.py index b803d7fea1..e637b53212 100644 --- a/monai/networks/blocks/dynunet_block.py +++ b/monai/networks/blocks/dynunet_block.py @@ -219,8 +219,7 @@ def __init__(self, spatial_dims: int, in_channels: int, out_channels: int): ) def forward(self, inp): - out = self.conv(inp) - return out + return self.conv(inp) def get_conv_layer(