Extracting values of middle layers that hasnot been flagged as output

I’ve trained a code like the one in bellow for 1000 epochs but I forgot to flag the desired variable as the output of my model, is there any way to extract during the test time? I want to visualize it but don’t know what I need to do (unfortunately the name of all the inputs and outputs are the same, I don’t know how I should find it!!)

class Net(nn.Module):
   def __init__(self):
      super(Net, self).__init__()
      self.conv1 = nn.Conv2d(...)
      self.conv2 = nn.Conv2d(....)
      self.conv3 = nn.Conv2d(....)

    def forward(self, x1):
      x1 = self.conv1(x1)
      x1 = self.conv2(x1)  <-------------------- the variable that I want to visualize
      x1 = self.conv3(x1)
      return x1

Can you try returning two outputs instead?


    def forward(self, x1):
      x1 = self.conv1(x1)
      saved = self.conv2(x1)
      x1 = self.conv3(saved)
      return x1, saved

No I can not train it again, it’s now a pretrained network that I want to visualize outputs of it’s hidden layers.

What happens if you define a second model with the additional outputs and just load the weights of the first model? There aren’t any additional parameters introduced here.

Thank you so much for your response,