-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcnnTest.m
26 lines (24 loc) · 850 Bytes
/
cnnTest.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
function cnnTest(cnn,images,labels)
numImages = length(images);
activations = images;
numLayers = size(cnn.layers);
for l = 1:numLayers
layer = cnn.layers{l};
if(strcmp(layer.type,'c'))%convolutional layer
activations = cnnConvolve4D(activations,layer.W,layer.b);
else
activations = cnnPool(layer.poolDim,activations);
end
layer.activations = activations;
cnn.layers{l} = layer;
end
%softmax
activations = reshape(activations,[],numImages);
probs = exp(bsxfun(@plus, cnn.Wd * activations, cnn.bd));
sumProbs = sum(probs, 1);
probs = bsxfun(@times, probs, 1 ./ sumProbs);
[~,preds] = max(probs,[],1);
preds = preds';
acc = sum(preds==labels)/length(preds);
fprintf('Accuracy is %f\n',acc);
end