Skip to content

Commit b624fb9

Browse files
committed
v2.3.1: uses new implementation of architecture definition in plans. Makes it easier to plan custom architectures. Fully backwards compatible with old plans but will complain if you dont update them
1 parent 7cec1a5 commit b624fb9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

nnunetv2/utilities/get_network_from_plans.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pydoc
2+
import warnings
23
from typing import Union
34

5+
from nnunetv2.utilities.find_class_by_name import recursive_find_python_class
6+
from batchgenerators.utilities.file_and_folder_operations import join
7+
48

59
def get_network_from_plans(arch_class_name, arch_kwargs, arch_kwargs_req_import, input_channels, output_channels,
610
allow_init=True, deep_supervision: Union[bool, None] = None):
@@ -11,6 +15,18 @@ def get_network_from_plans(arch_class_name, arch_kwargs, arch_kwargs_req_import,
1115
architecture_kwargs[ri] = pydoc.locate(architecture_kwargs[ri])
1216

1317
nw_class = pydoc.locate(network_class)
18+
# sometimes things move around, this makes it so that we can at least recover some of that
19+
if nw_class is None:
20+
warnings.warn(f'Network class {network_class} not found. Attempting to locate it within '
21+
f'dynamic_network_architectures.architectures...')
22+
import dynamic_network_architectures
23+
nw_class = recursive_find_python_class(join(dynamic_network_architectures.__path__[0], "architectures"),
24+
network_class.split(".")[-1],
25+
'dynamic_network_architectures.architectures')
26+
if nw_class is not None:
27+
print(f'FOUND IT: {nw_class}')
28+
else:
29+
raise ImportError('Network class could not be found, please check/correct your plans file')
1430

1531
if deep_supervision is not None and 'deep_supervision' not in arch_kwargs.keys():
1632
arch_kwargs['deep_supervision'] = deep_supervision
@@ -24,4 +40,4 @@ def get_network_from_plans(arch_class_name, arch_kwargs, arch_kwargs_req_import,
2440
if hasattr(network, 'initialize') and allow_init:
2541
network.apply(network.initialize)
2642

27-
return network
43+
return network

nnunetv2/utilities/plans_handling/plans_handler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def __init__(self, configuration_dict: dict):
3636
if 'architecture' not in self.configuration.keys():
3737
warnings.warn("Detected old nnU-Net plans format. Attempting to reconstruct network architecture "
3838
"parameters. If this fails, rerun nnUNetv2_plan_experiment for your dataset. If you use a "
39-
"custom architecture, please downgrade nnU-Net yo v2.3 "
40-
"(https://github.com/MIC-DKFZ/nnUNet/releases/tag/v2.3) or update your plans.")
39+
"custom architecture, please downgrade nnU-Net to the version you implemented this "
40+
"or update your implementation + plans.")
4141
# try to build the architecture information from old plans, modify configuration dict to match new standard
4242
unet_class_name = self.configuration["UNet_class_name"]
4343
if unet_class_name == "PlainConvUNet":

0 commit comments

Comments
 (0)