-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestFnc.m
42 lines (28 loc) · 870 Bytes
/
testFnc.m
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
function [labels,scores,test_time] = testFnc(net, testFolder)
%Function used to get the class probabilties given a network and a
%(test) data path.
d_c= dir([testFolder, 'Cancer']);
d_c(1:2) =[];
d_n= dir([testFolder, 'Normal']);
d_n(1:2) =[];
pos = length(d_c);
neg = length(d_n);
net = vl_simplenn_move(net, 'gpu');
net.layers{end}.type = 'softmax';
labels= [ones(1,pos),2*ones(1,neg)];
scores = gpuArray(zeros(pos+neg,2));
t_st = tic;
for i=1:pos
im = gpuArray(single(importdata([testFolder,'Cancer/', d_c(i).name])));
res = vl_simplenn(net,single(im));
res2= reshape(res(end).x,2,1);
scores(i,:) = res2';
end;
for i=1:neg
im= gpuArray(single(importdata([testFolder,'Normal/', d_n(i).name])));
res = vl_simplenn(net,single(im));
res2= reshape(res(end).x,2,1);
scores(pos+i,:) = res2';
end;
test_time= toc(t_st);
scores = gather(scores);