Hello! I have this piece of code:
class View(nn.Module):
def __init__(self, size):
super(View, self).__init__()
self.size = size
def forward(self, tensor):
return tensor.view(self.size)
class Encoder(nn.Module):
def __init__(self):
super().__init__()
N = 32
self.encoder = nn.Sequential(
nn.Conv2d(3, N, 4, 2, 1),
nn.ReLU(True),
nn.Conv2d(N, N, 4, 2, 1),
nn.ReLU(True),
nn.Conv2d(N, 2*N, 4, 2, 1),
nn.ReLU(True),
nn.Conv2d(2*N, 2*N, 4, 2, 1),
nn.ReLU(True),
nn.Conv2d(2*N, 8*N, 4, 1),
nn.ReLU(True),
View((-1, 8*N*1*1)),
nn.Linear(8*N, 2),
)
def forward(self, x):
z = self.encoder(x)
return z
I take 64x64 images and return 2 numbers. I trained it to do what I need and it works well, but I would like now (for some other reason) to get the activations before the output i.e. the result of that flattening layer. So I would need the values of the 8*N dimensional vector, before the last matrix multiplication. How can I do this? Thank you!