diff --git a/nnunetv2/utilities/get_network_from_plans.py b/nnunetv2/utilities/get_network_from_plans.py index 8d10cb4a3..be79777fe 100644 --- a/nnunetv2/utilities/get_network_from_plans.py +++ b/nnunetv2/utilities/get_network_from_plans.py @@ -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): @@ -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 @@ -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 \ No newline at end of file + return network diff --git a/nnunetv2/utilities/plans_handling/plans_handler.py b/nnunetv2/utilities/plans_handling/plans_handler.py index 518a462f9..11b76dfcb 100644 --- a/nnunetv2/utilities/plans_handling/plans_handler.py +++ b/nnunetv2/utilities/plans_handling/plans_handler.py @@ -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":