From 1bd5c97c8708230132219fd023c4531c2fcb0f39 Mon Sep 17 00:00:00 2001 From: neuronflow <7048826+neuronflow@users.noreply.github.com> Date: Mon, 20 Sep 2021 23:10:23 +0200 Subject: [PATCH 1/3] dimension check for pretrained model weights This PR implements a dimension check, before trying to load pre-trained model weights. Signed-off-by: neuronflow --- monai/networks/nets/densenet.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/monai/networks/nets/densenet.py b/monai/networks/nets/densenet.py index e9f3b6d33e..0addd7dd88 100644 --- a/monai/networks/nets/densenet.py +++ b/monai/networks/nets/densenet.py @@ -306,7 +306,8 @@ def __init__( **kwargs, ) if pretrained: - # it only worked when `spatial_dims` is 2 + if kwargs["spatial_dims"] > 2: + raise NotImplementedError("Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions.") _load_state_dict(self, "densenet121", progress) @@ -329,7 +330,8 @@ def __init__( **kwargs, ) if pretrained: - # it only worked when `spatial_dims` is 2 + if kwargs["spatial_dims"] > 2: + raise NotImplementedError("Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions.") _load_state_dict(self, "densenet169", progress) @@ -352,7 +354,8 @@ def __init__( **kwargs, ) if pretrained: - # it only worked when `spatial_dims` is 2 + if kwargs["spatial_dims"] > 2: + raise NotImplementedError("Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions.") _load_state_dict(self, "densenet201", progress) From ad629d199c82cb49b9aa379602697cad08ac630e Mon Sep 17 00:00:00 2001 From: monai-bot Date: Mon, 20 Sep 2021 22:38:31 +0000 Subject: [PATCH 2/3] [MONAI] python code formatting Signed-off-by: monai-bot Signed-off-by: neuronflow --- monai/networks/nets/densenet.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/monai/networks/nets/densenet.py b/monai/networks/nets/densenet.py index 0addd7dd88..9936b727c7 100644 --- a/monai/networks/nets/densenet.py +++ b/monai/networks/nets/densenet.py @@ -307,7 +307,9 @@ def __init__( ) if pretrained: if kwargs["spatial_dims"] > 2: - raise NotImplementedError("Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions.") + raise NotImplementedError( + "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions." + ) _load_state_dict(self, "densenet121", progress) @@ -331,7 +333,9 @@ def __init__( ) if pretrained: if kwargs["spatial_dims"] > 2: - raise NotImplementedError("Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions.") + raise NotImplementedError( + "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions." + ) _load_state_dict(self, "densenet169", progress) @@ -355,7 +359,9 @@ def __init__( ) if pretrained: if kwargs["spatial_dims"] > 2: - raise NotImplementedError("Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions.") + raise NotImplementedError( + "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions." + ) _load_state_dict(self, "densenet201", progress) From ce481aaa9a7d8317011cb6ccd0d60cd1f0de9a14 Mon Sep 17 00:00:00 2001 From: neuronflow Date: Tue, 21 Sep 2021 16:55:25 +0200 Subject: [PATCH 3/3] multi line split error Signed-off-by: neuronflow --- monai/networks/nets/densenet.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/monai/networks/nets/densenet.py b/monai/networks/nets/densenet.py index 9936b727c7..dc2c07bb12 100644 --- a/monai/networks/nets/densenet.py +++ b/monai/networks/nets/densenet.py @@ -308,7 +308,8 @@ def __init__( if pretrained: if kwargs["spatial_dims"] > 2: raise NotImplementedError( - "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions." + "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not" + "provide pretrained models for more than two spatial dimensions." ) _load_state_dict(self, "densenet121", progress) @@ -334,7 +335,8 @@ def __init__( if pretrained: if kwargs["spatial_dims"] > 2: raise NotImplementedError( - "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions." + "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not" + "provide pretrained models for more than two spatial dimensions." ) _load_state_dict(self, "densenet169", progress) @@ -360,7 +362,8 @@ def __init__( if pretrained: if kwargs["spatial_dims"] > 2: raise NotImplementedError( - "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not provide pretrained models for more than two spatial dimensions." + "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not" + "provide pretrained models for more than two spatial dimensions." ) _load_state_dict(self, "densenet201", progress)