Sure.
This is how the model is loaded (having been previously downloaded from here and using a library for loading Caffe models in Torch7):
local cmodel = loadcaffe.load('Models/caffevgg16/VGG_ILSVRC_16_layers_deploy_old.prototxt', 'Models/caffevgg16/VGG_ILSVRC_16_layers_old.caffemodel', 'nn')
print(cmodel)
This is the output:
conv1_1: 64 3 3 3
conv1_2: 64 64 3 3
conv2_1: 128 64 3 3
conv2_2: 128 128 3 3
conv3_1: 256 128 3 3
conv3_2: 256 256 3 3
conv3_3: 256 256 3 3
conv4_1: 512 256 3 3
conv4_2: 512 512 3 3
conv4_3: 512 512 3 3
conv5_1: 512 512 3 3
conv5_2: 512 512 3 3
conv5_3: 512 512 3 3
fc6: 1 1 25088 4096
fc7: 1 1 4096 4096
fc8: 1 1 4096 1000
nn.Sequential {
[input -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> (11) -> (12) -> (13) -> (14) -> (15) -> (16) -> (17) -> (18) -> (19) -> (20) -> (21) -> (22) -> (23) -> (24) -> (25) -> (26) -> (27) -> (28) -> (29) -> (30) -> (31) -> (32) -> (33) -> (34) -> (35) -> (36) -> (37) -> (38) -> (39) -> (40) -> output]
(1): nn.SpatialConvolution(3 -> 64, 3x3, 1,1, 1,1)
(2): nn.ReLU
(3): nn.SpatialConvolution(64 -> 64, 3x3, 1,1, 1,1)
(4): nn.ReLU
(5): nn.SpatialMaxPooling(2x2, 2,2)
(6): nn.SpatialConvolution(64 -> 128, 3x3, 1,1, 1,1)
(7): nn.ReLU
(8): nn.SpatialConvolution(128 -> 128, 3x3, 1,1, 1,1)
(9): nn.ReLU
(10): nn.SpatialMaxPooling(2x2, 2,2)
(11): nn.SpatialConvolution(128 -> 256, 3x3, 1,1, 1,1)
(12): nn.ReLU
(13): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
(14): nn.ReLU
(15): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
(16): nn.ReLU
(17): nn.SpatialMaxPooling(2x2, 2,2)
(18): nn.SpatialConvolution(256 -> 512, 3x3, 1,1, 1,1)
(19): nn.ReLU
(20): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(21): nn.ReLU
(22): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(23): nn.ReLU
(24): nn.SpatialMaxPooling(2x2, 2,2)
(25): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(26): nn.ReLU
(27): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(28): nn.ReLU
(29): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(30): nn.ReLU
(31): nn.SpatialMaxPooling(2x2, 2,2)
(32): nn.View(-1)
(33): nn.Linear(25088 -> 4096)
(34): nn.ReLU
(35): nn.Dropout(0.500000)
(36): nn.Linear(4096 -> 4096)
(37): nn.ReLU
(38): nn.Dropout(0.500000)
(39): nn.Linear(4096 -> 1000)
(40): nn.SoftMax
}
Once loaded, model_stimuli and model_target are built in the following way:
model_stimuli = nn.Sequential()
model_target = nn.Sequential()
for i = 1, 30 do
model_stimuli:add(cmodel:get(i))
end
for i = 1, 31 do
model_target:add(cmodel:get(i))
end
The output of print(model_target) is: (model_stimuli is precisely the same without layer #31):
nn.Sequential {
[input -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> (11) -> (12) -> (13) -> (14) -> (15) -> (16) -> (17) -> (18) -> (19) -> (20) -> (21) -> (22) -> (23) -> (24) -> (25) -> (26) -> (27) -> (28) -> (29) -> (30) -> (31) -> output]
(1): nn.SpatialConvolution(3 -> 64, 3x3, 1,1, 1,1)
(2): nn.ReLU
(3): nn.SpatialConvolution(64 -> 64, 3x3, 1,1, 1,1)
(4): nn.ReLU
(5): nn.SpatialMaxPooling(2x2, 2,2)
(6): nn.SpatialConvolution(64 -> 128, 3x3, 1,1, 1,1)
(7): nn.ReLU
(8): nn.SpatialConvolution(128 -> 128, 3x3, 1,1, 1,1)
(9): nn.ReLU
(10): nn.SpatialMaxPooling(2x2, 2,2)
(11): nn.SpatialConvolution(128 -> 256, 3x3, 1,1, 1,1)
(12): nn.ReLU
(13): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
(14): nn.ReLU
(15): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
(16): nn.ReLU
(17): nn.SpatialMaxPooling(2x2, 2,2)
(18): nn.SpatialConvolution(256 -> 512, 3x3, 1,1, 1,1)
(19): nn.ReLU
(20): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(21): nn.ReLU
(22): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(23): nn.ReLU
(24): nn.SpatialMaxPooling(2x2, 2,2)
(25): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(26): nn.ReLU
(27): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(28): nn.ReLU
(29): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
(30): nn.ReLU
(31): nn.SpatialMaxPooling(2x2, 2,2)
}
To be honest, I’m still unsure about torch’s get method behaviour (I’m struggling with torch’s documentation); at first glance, I’d have thought it’s the same as doing the following in PyTorch:
model_stimuli = nn.Sequential(*list(model.features.children())[:-1])
model_target = nn.Sequential(*list(model.features.children()))
But, evidently, it’s not.
(I’ve searched for more topics on this matter, such as this one, and I’m currently trying different variations of it.)