-
Notifications
You must be signed in to change notification settings - Fork 5
/
5_test.lua
64 lines (52 loc) · 1.67 KB
/
5_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
52
53
54
55
56
57
58
59
60
61
62
63
64
----------------------------------------------------------------------
-- This script implements a test procedure, to report accuracy
-- on the test data. Nothing fancy here...
--
-- Clement Farabet
----------------------------------------------------------------------
require 'torch' -- torch
require 'xlua' -- xlua provides useful tools, like progress bars
require 'optim' -- an optimization package, for online and batch methods
----------------------------------------------------------------------
print '==> defining test procedure'
-- test function
function test()
-- local vars
local time = sys.clock()
-- averaged param use?
if average then
cachedparams = parameters:clone()
parameters:copy(average)
end
-- test over test data
print('==> testing on test set:')
for t = 1,testData:size() do
-- disp progress
xlua.progress(t, testData:size())
-- get new sample
local input = testData.data[t]:double()
local target = testData.labels[t]
-- test sample
local pred = model:forward(input)
confusion:add(pred, target)
end
-- timing
time = sys.clock() - time
time = time / testData:size()
print("\n==> time to test 1 sample = " .. (time*1000) .. 'ms')
-- print confusion matrix
print(confusion)
-- update log/plot
testLogger:add{['% mean class accuracy (test set)'] = confusion.totalValid * 100}
if opt.plot then
testLogger:style{['% mean class accuracy (test set)'] = '-'}
testLogger:plot()
end
-- averaged param use?
if average then
-- restore parameters
parameters:copy(cachedparams)
end
-- next iteration:
confusion:zero()
end