Skip to content

Commit f31b55f

Browse files
dimension check for pretrained model weights (#2984)
* dimension check for pretrained model weights This PR implements a dimension check, before trying to load pre-trained model weights. Signed-off-by: neuronflow <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> Signed-off-by: neuronflow <[email protected]> * multi line split error Signed-off-by: neuronflow <[email protected]> Co-authored-by: monai-bot <[email protected]>
1 parent b791ed2 commit f31b55f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

monai/networks/nets/densenet.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ def __init__(
306306
**kwargs,
307307
)
308308
if pretrained:
309-
# it only worked when `spatial_dims` is 2
309+
if kwargs["spatial_dims"] > 2:
310+
raise NotImplementedError(
311+
"Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not"
312+
"provide pretrained models for more than two spatial dimensions."
313+
)
310314
_load_state_dict(self, "densenet121", progress)
311315

312316

@@ -329,7 +333,11 @@ def __init__(
329333
**kwargs,
330334
)
331335
if pretrained:
332-
# it only worked when `spatial_dims` is 2
336+
if kwargs["spatial_dims"] > 2:
337+
raise NotImplementedError(
338+
"Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not"
339+
"provide pretrained models for more than two spatial dimensions."
340+
)
333341
_load_state_dict(self, "densenet169", progress)
334342

335343

@@ -352,7 +360,11 @@ def __init__(
352360
**kwargs,
353361
)
354362
if pretrained:
355-
# it only worked when `spatial_dims` is 2
363+
if kwargs["spatial_dims"] > 2:
364+
raise NotImplementedError(
365+
"Parameter `spatial_dims` is > 2 ; currently PyTorch Hub does not"
366+
"provide pretrained models for more than two spatial dimensions."
367+
)
356368
_load_state_dict(self, "densenet201", progress)
357369

358370

0 commit comments

Comments
 (0)