Skip to content

Access UNet bottleneck to add a second head for another loss calculation #949

Answered by KumoLiu
hellebe asked this question in General
Discussion options

You must be logged in to vote

Hi @hellebe,
Since both UNet and DynUNet were rewritten in a recursive manner. It may not be easy to get the bottom latent layer.
Here, I showed an ugly way to access the bottom bottleneck. Hope it may help.

from monai.networks.nets import UNet

net = UNet(spatial_dims=3, in_channels=1, out_channels=2, channels=(32,64,128,256), strides=(2,2,2))

#! hard code
print(net.model[1].submodule[1].submodule[1].submodule)

#! iterate it
module_names  = ["model",] + ["submodule"] * 3
for name in module_names[:-1]:
    net = net.get_submodule(name)[1]
print(net.submodule)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hellebe
Comment options

Answer selected by hellebe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants