09b6ca0ad0
WIP #3. Added import tests WIP #3 Added more test-cases WIP #3 Added more tests WIP #3. Fixed concat.lua test WIP #3 minor changes WIP #3 Fixed concat-parallel.lua WIP #3 Added check-model helper WIP #3 Added more tests for model checker WIP #3 Added extra tests WIP #3 Changed check-model to GraphChecker WIP #3. multiple cases fail for ImportTorch... WIP #3 Fixed ImportTorch batch test case running WIP #3 Changed graph checker to use gme path for id WIP #3 Updated tests WIP #3. Tweaked to get all examples working locally w/ 'th' WIP #3 Fixed tests
56 linhas
1.8 KiB
Lua
56 linhas
1.8 KiB
Lua
-- thanks to https://github.com/soumith/imagenet-multiGPU.torch for this example
|
|
require 'nn'
|
|
local modelType = 'A' -- on a titan black, B/D/E run out of memory even for batch-size 32
|
|
|
|
-- Create tables describing VGG configurations A, B, D, E
|
|
local cfg = {}
|
|
if modelType == 'A' then
|
|
cfg = {64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'}
|
|
elseif modelType == 'B' then
|
|
cfg = {64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'}
|
|
elseif modelType == 'D' then
|
|
cfg = {64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', 512, 512, 512, 'M'}
|
|
elseif modelType == 'E' then
|
|
cfg = {64, 64, 'M', 128, 128, 'M', 256, 256, 256, 256, 'M', 512, 512, 512, 512, 'M', 512, 512, 512, 512, 'M'}
|
|
else
|
|
error('Unknown model type: ' .. modelType .. ' | Please specify a modelType A or B or D or E')
|
|
end
|
|
|
|
local features = nn.Sequential()
|
|
do
|
|
local iChannels = 3;
|
|
for k,v in ipairs(cfg) do
|
|
if v == 'M' then
|
|
features:add(nn.SpatialMaxPooling(2,2,2,2))
|
|
else
|
|
local oChannels = v;
|
|
local conv3 = nn.SpatialConvolution(iChannels,oChannels,3,3,1,1,1,1);
|
|
features:add(conv3)
|
|
features:add(nn.ReLU(true))
|
|
iChannels = oChannels;
|
|
end
|
|
end
|
|
end
|
|
|
|
-- features:cuda()
|
|
-- features = makeDataParallel(features, nGPU) -- defined in util.lua
|
|
|
|
local classifier = nn.Sequential()
|
|
classifier:add(nn.View(512*7*7))
|
|
classifier:add(nn.Linear(512*7*7, 4096))
|
|
classifier:add(nn.Threshold(0, 0.000001))
|
|
classifier:add(nn.BatchNormalization(4096, 0.001))
|
|
classifier:add(nn.Dropout(0.5))
|
|
classifier:add(nn.Linear(4096, 4096))
|
|
classifier:add(nn.Threshold(0, 0.000001))
|
|
classifier:add(nn.BatchNormalization(4096, 0.001))
|
|
classifier:add(nn.Dropout(0.5))
|
|
classifier:add(nn.Linear(4096, 1000))
|
|
classifier:add(nn.LogSoftMax())
|
|
-- classifier:cuda()
|
|
|
|
local model = nn.Sequential()
|
|
model:add(features):add(classifier)
|
|
|
|
return model
|