I registered some forward_hooks to my model like that:
vgg16.features[3].register_forward_hook(get_layer3)
The get_layer3-Function gave me the results I wanted.
But I thought it’s cleaner when I register the hook inside my model class:
class Net(nn.Module):
def __init__(self, vgg):
super(Net, self).__init__()
self.features = vgg.features
self.classifier = nn.Sequential(
nn.Conv1d(960, 4096, 1),
nn.ReLU(True),
nn.Conv1d(4096, 4096, 1),
nn.ReLU(True),
nn.Conv1d(4096, 3, 1)
)
vgg.features[3].register_forward_hook(self.get_layer3)
def forward(self, x):
....
def get_layer3(self, input, output):
output_layer3 = output.data
But now I get this error:
TypeError: get_layer3() takes 3 positional arguments but 4 were given
When I remove the paramter self from the function get_layer3 so it looks like this:
def get_layer3(input, output):
output_layer3 = output.data
I get the error:
TypeError: get_layer3() takes 3 positional arguments but 2 were given
So the self-parameter contains somehow to parameters when it’s defined inside my class and one parameter, when is defined outside my class.
Can someone tell me how I can find out why this is so?