Obtaining intermediate layers' activation values given input example(s)
<p>Suppose I have defined my sequential model as follow:</p>

<pre><code>require 'nn'
net = nn.Sequential()
net:add(nn.SpatialConvolution(1, 6, 5, 5)) -- 1 input image channel, 6 output channels, 5x5 convolution kernel
net:add(nn.ReLU())                       -- non-linearity 
net:add(nn.SpatialMaxPooling(2,2,2,2))     -- A max-pooling operation that looks at 2x2 windows and finds the max.
net:add(nn.SpatialConvolution(6, 16, 5, 5))
net:add(nn.ReLU())                       -- non-linearity 
net:add(nn.SpatialMaxPooling(2,2,2,2))
net:add(nn.View(16*5*5))                    -- reshapes from a 3D tensor of 16x5x5 into 1D tensor of 16*5*5
net:add(nn.Linear(16*5*5, 120))             -- fully connected layer (matrix multiplication between input and weights)
net:add(nn.ReLU())                       -- non-linearity 
net:add(nn.Linear(120, 84))
net:add(nn.ReLU())                       -- non-linearity 
net:add(nn.Linear(84, 10))                   -- 10 is the number of outputs of the network (in this case, 10 digits)
net:add(nn.LogSoftMax())                     -- converts the output to a log-probability. Useful for classification problems
</code></pre>

<p>And here's the model printed:</p>

<pre><code>net
nn.Sequential {
  [input -&gt; (1) -&gt; (2) -&gt; (3) -&gt; (4) -&gt; (5) -&gt; (6) -&gt; (7) -&gt; (8) -&gt; (9) -&gt; (10) -&gt; (11) -&gt; (12) -&gt; (13) -&gt; output]
  (1): nn.SpatialConvolution(1 -&gt; 6, 5x5)
  (2): nn.ReLU
  (3): nn.SpatialMaxPooling(2x2, 2,2)
  (4): nn.SpatialConvolution(6 -&gt; 16, 5x5)
  (5): nn.ReLU
  (6): nn.SpatialMaxPooling(2x2, 2,2)
  (7): nn.View(400)
  (8): nn.Linear(400 -&gt; 120)
  (9): nn.ReLU
  (10): nn.Linear(120 -&gt; 84)
  (11): nn.ReLU
  (12): nn.Linear(84 -&gt; 10)
  (13): nn.LogSoftMax
}
</code></pre>

<p>Simply using <code>net:forward(input)</code> returns the last layer's output after LogSoftMax has been applied to which is what I do not want. Instead, I would like to get the activations of some of the intermediate layers (e.g. module 6). </p>

<p>So, How can I get the activations of each of the intermediate layers when feeding an input? i.e. I feed an input example to the network and want to extract the activation results of the 6th layer (a convolutional layer), not just the final layer.</p>

<p>Thanks</p>