Most of the times, we want to extract nested module in architecture; while some modules support indexing (Sequential), some don't. This function enables you to access nested modules in a numpy-like indexing. When coupled with arch_summary
, we can effortlessly explore the pytorch models.
from torchvision.models import shufflenet_v2_x1_0, resnet50
arch_summary
can handle named as well as simple Sequential modules with different behavior. Indices could be used to quickly navigate the architecture, module names are also introduced in summary if available. xresnet50
is the architecture defined in fastai2
and is extending Sequential
arch_summary(xresnet50)
get_module
could be used to extract a specific module nested deep within hierarchy.
get_module(xresnet50,[4,0])
And if you really want to go deeper, you may set verbose=True
and arch_summary
will go 2 depth down. For the simplicity, I'm keeping it to the depth of 2, since you can always have a detailed summary using fastai2
's patched summary method on module
arch_summary(xresnet50,verbose=True)
Now let's quickly review a named_module architecture and how arch_summary
handles that information
arch_summary(shufflenet_v2_x1_0)
Refer arch_explore for more examples