forked from Moodstocks/gtsrb
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.lua
54 lines (46 loc) · 1.62 KB
/
main.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
local dataset = require 'dataset'
local network = require 'network'
local training = require 'training_optim'
local testing = require 'testing'
local matching = require 'matching'
local pathx = require 'pl.path'
require 'torch'
print('Reading training dataset.')
local train_dataset
local val_dataset
local test_dataset
if pathx.exists('train_dataset.bin') and pathx.exists('val_dataset.bin') then
print('Using existing train and validation datasets.')
train_dataset = torch.load('train_dataset.bin')
val_dataset = torch.load('val_dataset.bin')
else
train_dataset, val_dataset = dataset.get_dataset(false, true, false)
torch.save('train_dataset.bin', train_dataset)
torch.save('val_dataset.bin', val_dataset)
end
print('Using ' .. train_dataset.nbr_elements .. ' training samples.')
print('Using ' .. val_dataset.nbr_elements .. ' validation samples.')
print('Reading testing dataset.')
local test_dataset
if pathx.exists('test_dataset.bin') then
print('Using existing test dataset.')
test_dataset = torch.load('test_dataset.bin')
else
test_dataset = dataset.get_dataset(true, false, false)
torch.save('test_dataset.bin', test_dataset)
end
print('Using ' .. test_dataset.nbr_elements .. ' testing samples.')
local cnn
if pathx.exists('model.bin') then
print('Using pretrained network.')
cnn = torch.load('model.bin')
else
cnn = network.get_network_multiscale()
print('Training network.')
training.train_network(cnn, train_dataset, val_dataset)
print('Saving network.')
torch.save('model.bin', cnn)
end
print('Testing network.')
testing.test_network(cnn, test_dataset)
matching.test_matching(cnn, 4, test_dataset)