From e50f585d8c93835f75e8124ef98c4b76e5455ad9 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 27 Jul 2021 13:34:50 +0800 Subject: [PATCH 1/3] [DLMED] enhance doc-string Signed-off-by: Nic Ma --- monai/networks/nets/unet.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/monai/networks/nets/unet.py b/monai/networks/nets/unet.py index 9e3538c2b3..c4c5afe720 100644 --- a/monai/networks/nets/unet.py +++ b/monai/networks/nets/unet.py @@ -64,7 +64,10 @@ def __init__( Note: The acceptable spatial size of input data depends on the parameters of the network, to set appropriate spatial size, please check the tutorial for more details: https://github.com/Project-MONAI/tutorials/blob/master/modules/UNet_input_size_constrains.ipynb. - Typically, applying `resize`, `pad` or `crop` transforms can help adjust the spatial size of input data. + Typically, when using a stride of 2 in down / up sampling, the output dimensions are either half of the + input when downsampling, and twice when upsampling, so if have N numbers of layers in the network, + the inputs must have spatial dimensions that are all multiples of 2^N. + Usually, applying `resize`, `pad` or `crop` transforms can help adjust the spatial size of input data. """ super().__init__() From 0940e4533c2848fd390b6d658bd65ae601945f86 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 27 Jul 2021 13:39:12 +0800 Subject: [PATCH 2/3] [DLMED] enhance the sanity check Signed-off-by: Nic Ma --- monai/networks/nets/unet.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monai/networks/nets/unet.py b/monai/networks/nets/unet.py index c4c5afe720..0967b7d8f1 100644 --- a/monai/networks/nets/unet.py +++ b/monai/networks/nets/unet.py @@ -74,11 +74,11 @@ def __init__( if len(channels) < 2: raise ValueError("the length of `channels` should be no less than 2.") - delta = len(strides) - len(channels) - if delta < -1: + delta = len(strides) - (len(channels) - 1) + if delta < 0: raise ValueError("the length of `strides` should equal to `len(channels) - 1`.") - if delta >= 0: - warnings.warn(f"`len(strides) >= len(channels)`, the last {delta + 1} values of strides will not be used.") + if delta > 0: + warnings.warn(f"`len(strides) > len(channels) - 1`, the last {delta} values of strides will not be used.") if isinstance(kernel_size, Sequence): if len(kernel_size) != dimensions: raise ValueError("the length of `kernel_size` should equal to `dimensions`.") From ceae4f593040d3a765c3376ae537973909650125 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 27 Jul 2021 23:06:13 +0800 Subject: [PATCH 3/3] [DLMED] update according to comments Signed-off-by: Nic Ma --- monai/networks/nets/unet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/networks/nets/unet.py b/monai/networks/nets/unet.py index 0967b7d8f1..158b154042 100644 --- a/monai/networks/nets/unet.py +++ b/monai/networks/nets/unet.py @@ -65,7 +65,7 @@ def __init__( to set appropriate spatial size, please check the tutorial for more details: https://github.com/Project-MONAI/tutorials/blob/master/modules/UNet_input_size_constrains.ipynb. Typically, when using a stride of 2 in down / up sampling, the output dimensions are either half of the - input when downsampling, and twice when upsampling, so if have N numbers of layers in the network, + input when downsampling, or twice when upsampling. In this case with N numbers of layers in the network, the inputs must have spatial dimensions that are all multiples of 2^N. Usually, applying `resize`, `pad` or `crop` transforms can help adjust the spatial size of input data.