I am trying to visualize some intermediate (attention) layers from a network that I created myself.
I already tried the approaches from Accessing intermediate layers of a pretrained network forward? and Extract Features from models made with nn.ModuleList but to no avail.
Somehow I am not possible to iterate over my nn.ModuleList
:
class Attention_Maps(nn.Module):
def __init__(self):
super(Attention_Maps, self).__init__()
# Load my model
model = myModelClass
model = model.load_from_checkpoint("<path_to_my_model>.ckpt")
# With vgg_modules it works, despite being the same type
vgg_modules = list(vgg16(pretrained=True).features)
image_modules = list(model.children())
self.modules = nn.ModuleList(image_modules)
def forward(self, x):
results = []
# TypeError here in enumerate
for i, model in enumerate(self.modules):
x = model(x)
if i in {1, 3, 5, 7, 9}:
results.append(x)
return results
This results in the following error:
TypeError: 'method' object is not iterable
The weird thing is that vgg_modules
and image_modules
are the same type, so I don’t expect them to behave differently.
Am I doing something wrong?