Last active
July 12, 2016 11:44
-
-
Save nagadomi/15849fb2711de78c6bf6 to your computer and use it in GitHub Desktop.
mavenlin's 3-layer NIN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cunn' | |
require './lib/SpatialAveragePooling' | |
-- reference: https://gist.github.com/mavenlin/e56253735ef32c3c296d | |
local function normal_init(m, u, s, bias) | |
m.weight:normal(u, s) | |
if bias == nil then | |
m.bias:normal(u, s) | |
else | |
m.bias:fill(bias) | |
end | |
return m | |
end | |
-- 3-layer NIN for 32x32 | |
function nin3layer_model() | |
local model = nn.Sequential() | |
local final_mlpconv_layer = nil | |
model:add(normal_init(nn.SpatialConvolutionMM(3, 192, 5, 5, 1, 1, 2), 0, 0.05)) | |
model:add(nn.ReLU()) | |
model:add(normal_init(nn.SpatialConvolutionMM(192, 160, 1, 1), 0, 0.05, 0)) | |
model:add(nn.ReLU()) | |
model:add(normal_init(nn.SpatialConvolutionMM(160, 96, 1, 1), 0, 0.05, 0)) | |
model:add(nn.ReLU()) | |
model:add(nn.SpatialMaxPooling(2, 2, 2, 2)) | |
model:add(nn.Dropout(0.5)) | |
model:add(normal_init(nn.SpatialConvolutionMM(96, 192, 5, 5, 1, 1, 2), 0, 0.05)) | |
model:add(nn.ReLU()) | |
model:add(normal_init(nn.SpatialConvolutionMM(192, 192, 1, 1), 0, 0.05, 0)) | |
model:add(nn.ReLU()) | |
model:add(normal_init(nn.SpatialConvolutionMM(192, 192, 1, 1), 0, 0.05, 0)) | |
model:add(nn.ReLU()) | |
-- model:add(nn.SpatialMaxPooling(2, 2, 2, 2)) -- cuda-convnet version uses maxpool | |
model:add(nn.MySpatialAveragePooling(192, 2, 2, 2, 2)) | |
model:add(nn.Dropout(0.5)) | |
model:add(normal_init(nn.SpatialConvolutionMM(192, 192, 3, 3, 1, 1, 1), 0, 0.05, 0)) | |
model:add(nn.ReLU()) | |
model:add(normal_init(nn.SpatialConvolutionMM(192, 192, 1, 1), 0, 0.05, 0)) | |
model:add(nn.ReLU()) | |
final_mlpconv_layer = normal_init(nn.SpatialConvolutionMM(192, 10, 1, 1, 1, 1), 0, 0.01, 0) | |
model:add(final_mlpconv_layer) | |
model:add(nn.ReLU()) | |
model:add(nn.MySpatialAveragePooling(10, 8, 8, 8, 8)) | |
model:add(nn.Reshape(10)) | |
model:add(nn.SoftMax()) | |
final_mlpconv_layer.weight:abs() | |
final_mlpconv_layer.bias:abs() | |
return model | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code did not get good result.