File: version001.lua

package info (click to toggle)
deepboof 0.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,892 kB
  • sloc: java: 14,256; python: 50; makefile: 7; sh: 3
file content (70 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'torch'
require 'nn'

if opt.type == 'cuda' then
   require 'cunn'
end

----------------------------------------------------------------------
print(sys.COLORS.red ..  '==> construct CNN')


-- Raw training set
-- This gets around 70.6 % on test starting around epoc 115
--                  73.6 % on training
--
-- With horizontal flipping
-- This gets around 74.5 % on test starting around epoc 156
--                  72.1 % on training
--
-- th run.lua -r 1.48242 --sgdLearningRateDecay 0.00195 --sgdMomentum 0.09982 --sgdWeightDecay 2.46e-05 -s full

local CNN = nn.Sequential()
CNN:add(nn.SpatialConvolution(3, 10, 3, 3, 1, 1, 1, 1))
CNN:add(nn.ReLU())
CNN:add(nn.SpatialDropout(0.2))
CNN:add(nn.SpatialMaxPooling(2,2,2,2))
CNN:add(nn.SpatialBatchNormalization(10))
CNN:add(nn.SpatialConvolution(10, 20, 3, 3, 1, 1, 1, 1))
CNN:add(nn.ReLU())
CNN:add(nn.SpatialDropout(0.2))
CNN:add(nn.SpatialMaxPooling(2,2,2,2))
CNN:add(nn.SpatialBatchNormalization(20))
CNN:add(nn.SpatialConvolution(20, 40, 3, 3, 1, 1, 1, 1))
CNN:add(nn.ReLU())
CNN:add(nn.SpatialDropout(0.25))
CNN:add(nn.SpatialBatchNormalization(40))
CNN:add(nn.View(40*8*8))

local classifier = nn.Sequential()
classifier:add(nn.Linear(40*8*8, 500))
classifier:add(nn.BatchNormalization(500))
classifier:add(nn.ReLU())
classifier:add(nn.Dropout(0.5))
classifier:add(nn.Linear(500, 10))
classifier:add(nn.LogSoftMax())


local model = nn.Sequential()
model:add(CNN)
model:add(classifier)

-- Loss: NLL
local loss = nn.ClassNLLCriterion()


----------------------------------------------------------------------
print(sys.COLORS.red ..  '==> here is the CNN:')
print(model)

if opt.type == 'cuda' then
   model:cuda()
   loss:cuda()
end

-- return package:
return {
   model = model,
   loss = loss,
}