Hey,
Already got a lot of helpful things form this form so many thanks!
I found the following function from ptrblck to visualize a feature map:
activation = {}
def get_activation(name):
def hook(model, input, output):
activation[name] = output.detach()
return hook
This worked perfectly for my ResNet50, and now i wanted to try this on the discriminator of a GAN.
This is model is made up like this:
class Discriminator128(nn.Module):
def __init__(self, ngpu):
super(Discriminator128, self).__init__()
self.ngpu = ngpu
self.main = nn.Sequential(
# input is (nc) x 128 x 128
nn.Conv2d(nc, ndf, 4, 2, 1, bias=False),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*2) x 64 x 64
nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 2),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*4) x 32 x 32
nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 4),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*8) x 16 x 16
nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 8),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*16) x 8 x 8
nn.Conv2d(ndf * 8, ndf * 16, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 16),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*8) x 4 x 4
nn.Conv2d(ndf * 16, 1, 4, 1, 0, bias=False),
nn.Sigmoid()
)
def forward(self, input):
return self.main(input)
But when I try to get the activation in the following way:
act = activation['main[0]'].squeeze()
I get:
KeyError: 'main[14]'
Anybody who can help me out?
Thanks!