-
Notifications
You must be signed in to change notification settings - Fork 81
/
testWithPreTrainedNetwork.lua
54 lines (44 loc) · 1.63 KB
/
testWithPreTrainedNetwork.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
-- Example of how to test using a pre-trained network
-- Expects a directory containing two or more directories
-- One directory contains all the malware
-- The other directory contains all the benign software
-- given a model that has already been trained
-- and a directory containing programs - classify into malware / benign
require 'nn'
require 'optim'
require 'nngraph'
require 'cunn'
require 'cutorch'
require 'readMalwareData'
require 'testModel'
cmd = torch.CmdLine()
cmd:option('-useCUDA',false,'use CUDA optimisation')
cmd:option('-dataDir','./malwareDataset/','directory with the android programs to classify')
cmd:option('-modelPath','./trainedNets/model.th7','path to model to use for testing')
opt = cmd:parse(arg)
print('loading model from disk')
savedModel = torch.load(opt.modelPath)
print('loaded model')
print(savedModel.trainedModel)
-- we need these values to correctly prepare the files when reading from disk
opt.programLen = savedModel.opt.programLen
opt.kernelLength = savedModel.opt.kernelLength
opt.maxSequenceLength = savedModel.opt.maxSequenceLength
print('reading data from disk')
allData = readMalwareData(opt.dataDir,savedModel.metaData)
if opt.useCUDA then
savedModel.trainedModel:cuda()
end
savedModel.trainedModel:evaluate()
print('starting test')
testResult,confmat,time = testModel(allData,savedModel.trainedModel,savedModel.metaData.testInds,0)
print('Results')
print('f-score ',testResult.fscore)
print('precision ',testResult.prec)
print('recall ',testResult.recall)
print('accuracy ',testResult.accuracy)
print('--')
print('Confusion Matrix')
print(confmat)
print('--')
print('time to complete test (s) :',time)