creating a max-pooling layer using nested loop.

조회 수: 4 (최근 30일)
Janrex Pensader
Janrex Pensader 2018년 12월 27일
답변: Image Analyst 2018년 12월 28일
I am trying to make a max pooling layer with a 3x3 filter and stride 3. I'm trying to only use for loops for this code to work. here is my code.
main = [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];
temp=0;
%temporary var for stride
tmpX=0;
tmpY=0;
for x=1:size(main,1)/3
for y=1:size(main,2)/3
for cx=1:3
for cy=1:3
%stride by 3
cy = cy+tmpY;
cx = cx+tmpX;
if main(cx,cy)>temp
temp = main(cx,cy)
end
end
end
if y == size(main,2)/3
tmpY=0;
tmpX=tmpX+3;
else
tmpY=tmpY+3;
end
end
end
I'm using the matrix 'main' as a sample input for the pooling, the program should give a 2x2 matrix output of [15,18,33,36] but I'm getting [15,18,19,0] ad an error message that says 'Index in position 1 exceeds array bounds (must not exceed 6).'

답변 (1개)

Image Analyst
Image Analyst 2018년 12월 28일
Just look at what the variables are. cx is 7 and main is only 6 wide.
By the way, matrices have the horizontal (column) index second, not first like you have it. So matrices are main(y, x) NOT main(x, y).

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by