Can I get the middle layer's output if I use the Sequential module?

You could just iterate the application yourself:

x = someinput
for l in vgg.features.modules():
  x = l(x)

and keep what you want.
You can slice the modules by wrapping the in a list, so:

modulelist = list(vgg.features.modules())
for l in modulelist[:5]:
  x = l(x)
keep = x
for l in modulelist[5:]:
  x = l(x)

Best regards

Thomas

12 Likes