forked from toshi-k/kaggle-denoising-dirty-documents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_model.lua
89 lines (64 loc) · 1.92 KB
/
2_model.lua
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---------- library ----------
require 'torch'
require 'image'
require 'nn'
require 'cunn'
---------- functions ----------
function newmodel()
-- input dimensions
local nfeats = 1
-- filter size
local filtsize = 3
-- hidden units
local nstates = {96,96,96,96,96}
-- model:
local model = nn.Sequential()
-- stage 1 : Convolution
model:add(nn.SpatialConvolutionMM(nfeats, nstates[1], filtsize, filtsize, 1, 1, 1))
model:add(nn.LeakyReLU(0.1))
-- stage 2 : Convolution
model:add(nn.SpatialConvolutionMM(nstates[1], nstates[2], 1, 1, 1))
model:add(nn.LeakyReLU(0.1))
-- stage 3 : Convolution
model:add(nn.SpatialConvolutionMM(nstates[2], nstates[3], filtsize, filtsize, 1, 1, 1))
model:add(nn.LeakyReLU(0.1))
-- stage 4 : Convolution
model:add(nn.SpatialConvolutionMM(nstates[3], nstates[4], 1, 1, 1))
model:add(nn.LeakyReLU(0.1))
-- stage 5 : Convolution
model:add(nn.SpatialConvolutionMM(nstates[4], nstates[5], filtsize, filtsize, 1, 1, 1))
model:add(nn.LeakyReLU(0.1))
-- stage 6 : Convolution
model:add(nn.SpatialConvolutionMM(nstates[5], 1, filtsize, filtsize, 1, 1, 1))
model:add(nn.LeakyReLU(0.001))
model:add(nn.AddConstant(-1,true))
model:add(nn.MulConstant(-1,true))
model:add(nn.LeakyReLU(0.001))
model:add(nn.MulConstant(-1,true))
model:add(nn.AddConstant(1,true))
return model
end
function newthreshold()
local model = nn.Sequential()
model:add(nn.ReLU())
model:add(nn.AddConstant(-1,true))
model:add(nn.MulConstant(-1,true))
model:add(nn.ReLU())
model:add(nn.MulConstant(-1,true))
model:add(nn.AddConstant(1,true))
return model
end
---------- main ----------
torch.setdefaulttensortype('torch.CudaTensor')
model = newmodel()
print(model)
thresholding = newthreshold()
print(thresholding)
-- loss function
criterion = nn.MSECriterion()
print '==> here is the loss function:'
print(criterion)
torch.setdefaulttensortype('torch.FloatTensor')
model:cuda()
thresholding:cuda()
criterion:cuda()