-
Notifications
You must be signed in to change notification settings - Fork 0
/
bpConvolutionCor.m
54 lines (43 loc) · 1.25 KB
/
bpConvolutionCor.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
function [inputerror,gradweights,gradbias] = bpConvolutionCor(input,errors,filters) % nxmxk input nxmxkxp filters
sizeofinput = size(input);
sizeoffilters = size(filters);
sizeoferrors = size(errors);
n = sizeofinput(1);
x = sizeofinput(2);
y = sizeofinput(3);
fn = sizeoffilters(1);
fd = sizeoffilters(2);
fx = sizeoffilters(3);
fy = sizeoffilters(4);
en= sizeoferrors(1);
ex= sizeoferrors(2);
ey = sizeoferrors(3);
gradweights = zeros(fn,fd,fx,fy);
gradbias = zeros(1,fn);
inputerror = zeros(n,x,y);
combinp = zeros(n,ex*ey,(x-ex+1)*(y-ey+1));
for i=1:n
coninp = im2col(reshape(input(i,:,:),x,y),[ex ey]);
combinp(i,:,:) = coninp;
end
for i=1:en
cf = im2col(reshape(errors(i,:,:),ex,ey),[ex ey]);
for j=1:n
outfilter = reshape(combinp(j,:,:),ex*ey,(x-ex+1)*(y-ey+1))'*cf;
temp = reshape(outfilter,1,1,(x-ex+1),(y-ey+1));
gradweights(i,j,:,:) = gradweights(i,j,:,:)+temp;
end
end
gradbias(:,:) = sum(sum(sum(gradweights,4),3),2)';
for i=1:en
curfil = reshape(filters(i,:,:,:),fd,fx,fy);
for j=1:ex
for k=1:ey
if errors(i,j,k) ~=0
errsum = errors(i,j,k)*curfil;
inputerror(:,j:(j+fx-1),k:(k+fy-1)) = inputerror(:,j:(j+fx-1),k:(k+fy-1)) + errsum;
end
end
end
end
end