Skip to content

Commit

Permalink
v2.3.1: uses new implementation of architecture definition in plans. …
Browse files Browse the repository at this point in the history
…Makes it easier to plan custom architectures. Fully backwards compatible with old plans but will complain if you dont update them
  • Loading branch information
FabianIsensee committed Feb 21, 2024
1 parent 7cec1a5 commit b624fb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion nnunetv2/utilities/get_network_from_plans.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import pydoc
import warnings
from typing import Union

from nnunetv2.utilities.find_class_by_name import recursive_find_python_class
from batchgenerators.utilities.file_and_folder_operations import join


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

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

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

return network
return network
4 changes: 2 additions & 2 deletions nnunetv2/utilities/plans_handling/plans_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def __init__(self, configuration_dict: dict):
if 'architecture' not in self.configuration.keys():
warnings.warn("Detected old nnU-Net plans format. Attempting to reconstruct network architecture "
"parameters. If this fails, rerun nnUNetv2_plan_experiment for your dataset. If you use a "
"custom architecture, please downgrade nnU-Net yo v2.3 "
"(https://github.com/MIC-DKFZ/nnUNet/releases/tag/v2.3) or update your plans.")
"custom architecture, please downgrade nnU-Net to the version you implemented this "
"or update your implementation + plans.")
# try to build the architecture information from old plans, modify configuration dict to match new standard
unet_class_name = self.configuration["UNet_class_name"]
if unet_class_name == "PlainConvUNet":
Expand Down

0 comments on commit b624fb9

Please sign in to comment.