-
Notifications
You must be signed in to change notification settings - Fork 80
/
train.lua
56 lines (51 loc) · 1.45 KB
/
train.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
require 'cutorch'
require './SETTINGS'
require './lib/minibatch_sgd'
require './lib/data_augmentation'
require './lib/preprocessing'
require './very_deep_model.lua'
function training()
local MAX_EPOCH = 20
local x = torch.load(string.format("%s/train_x.bin", DATA_DIR))
local y = torch.load(string.format("%s/train_y.bin", DATA_DIR))
local model = very_deep_model():cuda()
local criterion = nn.MSECriterion():cuda()
local sgd_config = {
learningRate = 1.0,
learningRateDecay = 5.0e-6,
momentum = 0.9,
xBatchSize = 64
}
local params = nil
print("data augmentation ..")
x, y = data_augmentation(x, y)
collectgarbage()
print("preprocessing ..")
params = preprocessing(x)
torch.save("models/preprocessing_params.bin", params)
collectgarbage()
for epoch = 1, MAX_EPOCH do
print("# " .. epoch)
if epoch == MAX_EPOCH then
-- final epoch
sgd_config.learningRateDecay = 0
sgd_config.learningRate = 0.01
end
model:training()
print(minibatch_sgd(model, criterion, x, y,
CLASSES, sgd_config))
model:evaluate()
torch.save(string.format("models/very_deep_%d.model", epoch), model)
epoch = epoch + 1
collectgarbage()
end
end
local cmd = torch.CmdLine()
cmd:text()
cmd:text("Kaggle-CIFAR10 Training")
cmd:text("Options:")
cmd:option("-seed", 11, 'fixed input seed')
local opt = cmd:parse(arg)
print(opt.seed)
torch.manualSeed(opt.seed)
training()