From b7427d27f4eac16a35dae2e0c8bef320e17b1d22 Mon Sep 17 00:00:00 2001 From: Paolo Zaffino Date: Thu, 12 Jan 2023 15:03:14 +0100 Subject: [PATCH 1/3] Fix constructors for DenseNet derived classes --- monai/networks/nets/densenet.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/monai/networks/nets/densenet.py b/monai/networks/nets/densenet.py index 40924cbc9a..406b7eb279 100644 --- a/monai/networks/nets/densenet.py +++ b/monai/networks/nets/densenet.py @@ -296,6 +296,9 @@ class DenseNet121(DenseNet): def __init__( self, + spatial_dims: int, + in_channels: int, + out_channels: int, init_features: int = 64, growth_rate: int = 32, block_config: Sequence[int] = (6, 12, 24, 16), @@ -303,7 +306,7 @@ def __init__( progress: bool = True, **kwargs, ) -> None: - super().__init__(init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) + super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) if pretrained: if kwargs["spatial_dims"] > 2: raise NotImplementedError( @@ -318,6 +321,9 @@ class DenseNet169(DenseNet): def __init__( self, + spatial_dims: int, + in_channels: int, + out_channels: int, init_features: int = 64, growth_rate: int = 32, block_config: Sequence[int] = (6, 12, 32, 32), @@ -325,7 +331,7 @@ def __init__( progress: bool = True, **kwargs, ) -> None: - super().__init__(init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) + super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) if pretrained: if kwargs["spatial_dims"] > 2: raise NotImplementedError( @@ -340,6 +346,9 @@ class DenseNet201(DenseNet): def __init__( self, + spatial_dims: int, + in_channels: int, + out_channels: int, init_features: int = 64, growth_rate: int = 32, block_config: Sequence[int] = (6, 12, 48, 32), @@ -347,7 +356,7 @@ def __init__( progress: bool = True, **kwargs, ) -> None: - super().__init__(init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) + super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) if pretrained: if kwargs["spatial_dims"] > 2: raise NotImplementedError( @@ -362,6 +371,9 @@ class DenseNet264(DenseNet): def __init__( self, + spatial_dims: int, + in_channels: int, + out_channels: int, init_features: int = 64, growth_rate: int = 32, block_config: Sequence[int] = (6, 12, 64, 48), @@ -369,7 +381,7 @@ def __init__( progress: bool = True, **kwargs, ) -> None: - super().__init__(init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) + super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) if pretrained: raise NotImplementedError("Currently PyTorch Hub does not provide densenet264 pretrained models.") From 978c1674bd459fbb5bac419fa47d00ff37ee71a2 Mon Sep 17 00:00:00 2001 From: Wenqi Li <831580+wyli@users.noreply.github.com> Date: Sat, 14 Jan 2023 19:01:03 +0000 Subject: [PATCH 2/3] Apply suggestions from code review Signed-off-by: 831580+wyli@users.noreply.github.com Signed-off-by: Wenqi Li <831580+wyli@users.noreply.github.com> --- monai/networks/nets/densenet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monai/networks/nets/densenet.py b/monai/networks/nets/densenet.py index 406b7eb279..508cfba46b 100644 --- a/monai/networks/nets/densenet.py +++ b/monai/networks/nets/densenet.py @@ -308,7 +308,7 @@ def __init__( ) -> None: super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) if pretrained: - if kwargs["spatial_dims"] > 2: + if spatial_dims > 2: raise NotImplementedError( "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not" "provide pretrained models for more than two spatial dimensions." @@ -333,7 +333,7 @@ def __init__( ) -> None: super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) if pretrained: - if kwargs["spatial_dims"] > 2: + if spatial_dims > 2: raise NotImplementedError( "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not" "provide pretrained models for more than two spatial dimensions." @@ -358,7 +358,7 @@ def __init__( ) -> None: super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) if pretrained: - if kwargs["spatial_dims"] > 2: + if spatial_dims > 2: raise NotImplementedError( "Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not" "provide pretrained models for more than two spatial dimensions." From d02335d34e4d57df1ba2cbeb410134e8de26a34a Mon Sep 17 00:00:00 2001 From: monai-bot Date: Sat, 14 Jan 2023 19:13:52 +0000 Subject: [PATCH 3/3] [MONAI] code formatting Signed-off-by: monai-bot --- monai/networks/nets/densenet.py | 40 +++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/monai/networks/nets/densenet.py b/monai/networks/nets/densenet.py index 508cfba46b..d822330347 100644 --- a/monai/networks/nets/densenet.py +++ b/monai/networks/nets/densenet.py @@ -306,7 +306,15 @@ def __init__( progress: bool = True, **kwargs, ) -> None: - super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) + super().__init__( + spatial_dims=spatial_dims, + in_channels=in_channels, + out_channels=out_channels, + init_features=init_features, + growth_rate=growth_rate, + block_config=block_config, + **kwargs, + ) if pretrained: if spatial_dims > 2: raise NotImplementedError( @@ -331,7 +339,15 @@ def __init__( progress: bool = True, **kwargs, ) -> None: - super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) + super().__init__( + spatial_dims=spatial_dims, + in_channels=in_channels, + out_channels=out_channels, + init_features=init_features, + growth_rate=growth_rate, + block_config=block_config, + **kwargs, + ) if pretrained: if spatial_dims > 2: raise NotImplementedError( @@ -356,7 +372,15 @@ def __init__( progress: bool = True, **kwargs, ) -> None: - super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) + super().__init__( + spatial_dims=spatial_dims, + in_channels=in_channels, + out_channels=out_channels, + init_features=init_features, + growth_rate=growth_rate, + block_config=block_config, + **kwargs, + ) if pretrained: if spatial_dims > 2: raise NotImplementedError( @@ -381,7 +405,15 @@ def __init__( progress: bool = True, **kwargs, ) -> None: - super().__init__(spatial_dims=spatial_dims, in_channels=in_channels, out_channels=out_channels, init_features=init_features, growth_rate=growth_rate, block_config=block_config, **kwargs) + super().__init__( + spatial_dims=spatial_dims, + in_channels=in_channels, + out_channels=out_channels, + init_features=init_features, + growth_rate=growth_rate, + block_config=block_config, + **kwargs, + ) if pretrained: raise NotImplementedError("Currently PyTorch Hub does not provide densenet264 pretrained models.")