Replies: 1 comment
-
One possible way is with forward hooks: import monai
import torch
net=monai.networks.nets.Densenet121(spatial_dims=2,in_channels=1,out_channels=1)
output_dict={}
def forward_hook(mod, inputs, outputs):
output_dict[mod]=outputs
def add_hooks(mod):
if isinstance(mod, monai.networks.nets.densenet._DenseLayer):
mod.register_forward_hook(forward_hook)
net.apply(add_hooks)
result=net(torch.rand(1,1,128,128))
print(output_dict) After the forward pass through the network |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello
I need to store the intermediate output of each dense block of monai densenet.
How can I do that?
Beta Was this translation helpful? Give feedback.
All reactions