Deriving The Structure Of A Pytorch Network
For my use case, I require to be able to take a pytorch module and interpret the sequence of layers in the module so that I can create a “connection” between the layers in some
Solution 1:
The information you are looking for is not stored in the nn.Module
, but rather in the grad_fn
attribute of the output tensor:
model = mymodel(channels)
pred = model(torch.rand((1, channels))
pred.grad_fn # all the information is in the computation graph of the output tensor
It is not trivial to extract this information. You might want to look at torchviz package that draws a nice graph from the grad_fn
information.
Post a Comment for "Deriving The Structure Of A Pytorch Network"