|
a |
|
b/code/trainDNN.lua |
|
|
1 |
require 'torch'; |
|
|
2 |
require 'nn'; |
|
|
3 |
require 'optim'; |
|
|
4 |
|
|
|
5 |
--cudaFlag = true |
|
|
6 |
cudaFlag = true |
|
|
7 |
|
|
|
8 |
if cudaFlag then |
|
|
9 |
require 'cutorch'; |
|
|
10 |
require 'cunn'; |
|
|
11 |
end |
|
|
12 |
|
|
|
13 |
-- parameters |
|
|
14 |
local batchSize = 200 -- batch size is approximate; actual batchSizes will vary by +/- N-1, where N is the number of classes |
|
|
15 |
local learningRate = 0.05 |
|
|
16 |
local learningRateDecay = 0.0005 |
|
|
17 |
local weightDecay = 0.000 |
|
|
18 |
local momentum = 0.9 |
|
|
19 |
local maxIteration = 20 |
|
|
20 |
local augment = true |
|
|
21 |
|
|
|
22 |
local trainFolder = '/home/andrew/mitosis/data/mitosis-train-large/' |
|
|
23 |
local testFolder = '/home/andrew/mitosis/data/mitosis-test/' |
|
|
24 |
|
|
|
25 |
dofile("data.lua") |
|
|
26 |
|
|
|
27 |
local classes, trainClassList, trainImagePaths = getImagePaths(trainFolder) |
|
|
28 |
local classes, testClassList, testImagePaths = getImagePaths(testFolder) |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
local classRatio = trainClassList[2]:size(1)/trainClassList[1]:size(1) |
|
|
32 |
local weights = torch.Tensor(2) |
|
|
33 |
weights[1] = classRatio |
|
|
34 |
weights[2] = 1 |
|
|
35 |
|
|
|
36 |
--[ |
|
|
37 |
-- first network |
|
|
38 |
-- define the model |
|
|
39 |
dofile("/home/andrew/mitosis/models/model1.lua") |
|
|
40 |
local net, criterion = model1(weights) |
|
|
41 |
if cudaFlag then |
|
|
42 |
net = net:cuda() |
|
|
43 |
criterion = criterion:cuda() |
|
|
44 |
end |
|
|
45 |
|
|
|
46 |
-- train the network |
|
|
47 |
dofile("train.lua") |
|
|
48 |
--net = torch.load('/home/andrew/mitosis/data/nets/dnn1_halfset_aug_20i_lr001.t7') |
|
|
49 |
--train(net, criterion, classes, trainClassList, imagePaths, batchSize, learningRate, maxIteration) |
|
|
50 |
--torch.save('/home/andrew/mitosis/data/nets/dnn1_fullset_aug_30i_lr05_mini200.t7', net) |
|
|
51 |
|
|
|
52 |
-- test the network |
|
|
53 |
dofile("test.lua") |
|
|
54 |
--test(classes, testClassList, imagePaths, batchSize, maxIteration) |
|
|
55 |
--]] |
|
|
56 |
|
|
|
57 |
|
|
|
58 |
-- second network |
|
|
59 |
-- define the model |
|
|
60 |
dofile("/home/andrew/mitosis/models/model2.lua") |
|
|
61 |
local net, criterion = model2(weights) |
|
|
62 |
if cudaFlag then |
|
|
63 |
net = net:cuda() |
|
|
64 |
criterion = criterion:cuda() |
|
|
65 |
end |
|
|
66 |
|
|
|
67 |
-- train the network |
|
|
68 |
dofile("train.lua") |
|
|
69 |
net = torch.load('/home/andrew/mitosis/data/nets/model2-pretrained-greedylayerwise2.t7') |
|
|
70 |
train(net, criterion, classes, trainClassList, trainImagePaths, batchSize, learningRate, learningRateDecay, weightDecay, momentum, maxIteration, classRatio, augment, netFolder) |
|
|
71 |
torch.save('/home/andrew/mitosis/data/nets/dnn2_fullset_aug_20i_lr05_lrd0005_m09_mini200_aeptgl.t7', net) |
|
|
72 |
|
|
|
73 |
-- test the network |
|
|
74 |
dofile("test.lua") |
|
|
75 |
--net = torch.load('/home/andrew/mitosis/data/nets/dnn2_fullset_aug_20i_lr05_mini200_aept.t7') |
|
|
76 |
test(net, classes, testClassList, testImagePaths, batchSize) |