From aa74c3abd51e534138496d62c1ae89d6484a3361 Mon Sep 17 00:00:00 2001 From: AIboy996 <2207854887@qq.com> Date: Thu, 19 Sep 2024 17:56:49 +0800 Subject: [PATCH] add an toy example for nnunetv2.utilities.get_network_from_plans --- nnunetv2/utilities/get_network_from_plans.py | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/nnunetv2/utilities/get_network_from_plans.py b/nnunetv2/utilities/get_network_from_plans.py index 67d3ca7ab..94a52266d 100644 --- a/nnunetv2/utilities/get_network_from_plans.py +++ b/nnunetv2/utilities/get_network_from_plans.py @@ -41,3 +41,34 @@ def get_network_from_plans(arch_class_name, arch_kwargs, arch_kwargs_req_import, network.apply(network.initialize) return network + +if __name__ == "__main__": + import torch + + model = get_network_from_plans( + arch_class_name="dynamic_network_architectures.architectures.unet.ResidualEncoderUNet", + arch_kwargs={ + "n_stages": 7, + "features_per_stage": [32, 64, 128, 256, 512, 512, 512], + "conv_op": "torch.nn.modules.conv.Conv2d", + "kernel_sizes": [[3, 3], [3, 3], [3, 3], [3, 3], [3, 3], [3, 3], [3, 3]], + "strides": [[1, 1], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]], + "n_blocks_per_stage": [1, 3, 4, 6, 6, 6, 6], + "n_conv_per_stage_decoder": [1, 1, 1, 1, 1, 1], + "conv_bias": True, + "norm_op": "torch.nn.modules.instancenorm.InstanceNorm2d", + "norm_op_kwargs": {"eps": 1e-05, "affine": True}, + "dropout_op": None, + "dropout_op_kwargs": None, + "nonlin": "torch.nn.LeakyReLU", + "nonlin_kwargs": {"inplace": True}, + }, + arch_kwargs_req_import=["conv_op", "norm_op", "dropout_op", "nonlin"], + input_channels=1, + output_channels=4, + allow_init=True, + deep_supervision=True, + ) + data = torch.rand((8, 1, 256, 256)) + target = torch.rand(size=(8, 1, 256, 256)) + outputs = model(data) # this should be a list of torch.Tensor \ No newline at end of file