forked from Moodstocks/gtsrb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lua
51 lines (43 loc) · 1.35 KB
/
test.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
----------------------------------------------------------------------
-- This script contains the main test function
--
-- It uses the model described in models/MSmodel.lua
--
-- Required :
-- + model
-- + test_set loaded with dataset.lua
--
-- Hugo Duthil
----------------------------------------------------------------------
require 'torch'
require 'optim'
function test()
-- Classes
local classes = {}
for i = 1, 43 do classes[i] = (i-1).."" end
-- this matrix records the current confusion across classes
local confusion = optim.ConfusionMatrix(classes)
confusion:zero()
print("Testing network")
-- shuffle validation test
shuffle = torch.randperm(test_set:size())
for i=1, test_set:size() do
-- progress bar
xlua.progress(i, test_set:size())
local input
-- extract Y channel
if params.use_3_channels then
input = test_set[shuffle[i]][1]
else
input = test_set[shuffle[i]][1][{{1}, {}, {}}]
end
local label = test_set[shuffle[i]][2]
-- the output needs to a xxxStorage of size 43 (not 1x43)
local output = model:forward(input)
-- add prediction to confusion matrix
confusion:add(output, label)
end
print(confusion)
torch.save("saves/confusion.t7", confusion)
confusion:zero()
end