-
Notifications
You must be signed in to change notification settings - Fork 12
/
runbp.m
61 lines (51 loc) · 1.26 KB
/
runbp.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function y = runbp(imgs_sample, imgs_sample_num, max_size)
% bp 网络训练
[a, b] = buildtrainset(imgs_sample, imgs_sample_num);
net = bpann(a', b');
% bp 测试
image_dir=dir('image/*.jpg');
for i = 1: length(image_dir)
str_name = image_dir(i).name;
imgs_test{i} = str_name(1:4);
end
rightnum = 0;
sumnum = 0;
for i = 1 : length(imgs_test)
img_name = imgs_test{i};
imgs = cutting(imread(['image/',img_name,'.jpg']), false);
if (length(imgs) == length(img_name))
for j = 1 : length(img_name)
tmp_num = str2num(img_name(j)) + 1;
%% 等大小化
temp = zeros(max_size);
imgs_size = size(imgs{j});
temp(1:imgs_size(1,1), 1:imgs_size(1,2)) = imgs{j};
imgs{j} = temp;
input_size = numel(temp);
testInput(j, :) = reshape(temp', input_size, 1);
end
size(testInput)
Y = sim( net , testInput' );
mans = [1:4];
for j = 1 : length(img_name)
ymax = 0;
yans = NaN;
for k = 1 : 10
if (ymax < Y(k, j))
ymax = Y(k, j);
yans = k;
end
end
mans(j) = yans-1;
sumnum = sumnum + 1;
if (mans(j) == str2num(img_name(j)))
rightnum = rightnum + 1;
end
end
img_name
mans
end
end
rightdata = [rightnum, sumnum-rightnum]
pie(rightdata, {'right', 'wrong'});
end