-
Notifications
You must be signed in to change notification settings - Fork 3
/
2_model.lua
60 lines (43 loc) · 1.82 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
----------------------------------------------------------------------
-- Author : Aysegul Dundar
-- This script demonstrates how to define a couple of different
-- models for Clustering Learning research
----------------------------------------------------------------------
require 'torch' -- torch
require 'nnx' -- provides all sorts of trainable modules/layers
----------------------------------------------------------------------
-- define network to train
--
print('<trainer> creating new network')
nk1 = 32 -- nb of features
is1,is2 = 5,5 -- size of kernels
ss1,ss2, ss3 = 2,2,4 -- size of subsamplers (strides)
fanin = 2 -- createCoCnxTable creates also 2*fanin connections
feat_group = 32 -- features per group (32=best in CIFAR nk1=32, fanin=2)
nhiddens = 256 -- nb of hidden features for top perceptron (0=linear classifier)
----------------------------------------------------------------------
print '==> construct model'
if opt.model == '1st-layer' then
model = nn.Sequential()
if opt.whitening then
model:add(nn.SpatialConvolution(ivch, nk1, is1, is1, is1, is1))
else
model:add(nn.SpatialConvolution(ivch, nk1, is1, is1))
end
model:add(nn.Threshold())
model:add(nn.SpatialMaxPooling(ss1,ss1,ss1,ss1))
elseif opt.model == '2nd-layer' then
model = nn.Sequential()
model:add(nn.SpatialConvolutionMap(cTable2, is2, is2))
model:add(nn.Threshold())
model:add(nn.SpatialMaxPooling(ss2,ss2,ss2,ss2))
elseif opt.model == '2mlp-classifier' then
outsize = 10 -- in CIFAR, SVHN datasets
model = nn.Sequential()
model:add(nn.Linear(l1netoutsize+cdatasize, nhiddens))
model:add(nn.Threshold())
model:add(nn.Linear(nhiddens,outsize))
else
error('unknown -model')
end
if verbose then print(model) end