pjreddie / darknet

Convolutional Neural Networks
http://pjreddie.com/darknet/
Other
25.69k stars 21.33k forks source link

reorg layer bug #2161

Open xiaotan3664 opened 4 years ago

xiaotan3664 commented 4 years ago

I'm confused by reorg_layer.c In my understanding, its funtion is when reverse=0,[n,c,h,w]->[n, ssc, h/s, w/s] and when reverse=1,[n,c,h,w]->[n, c/(ss), hs, w*s]

and reorg_xxx should be called with the shape[n,c,h,w] who has bigger c,,that is, reverse=0,reorg_cpu(net.input, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 0, l.output); reverse=1,reorg_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.output);

But in present code, reverse=0,reorg_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 0, l.output); reverse=1,reorg_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.output);

SantoSimone commented 4 years ago

I came up with this thought aswell, but can't understand if it's right or not. Maybe @AlexeyAB could enlighten us?

kongyanye commented 2 years ago

I was just confused with the same issue but after rethinking the code seems right to me. Here's the link: https://github.com/pjreddie/darknet/blob/a3714d0a2bf92c3dea84c4bea65b2b0c64dbc6b1/src/blas.c#L9

Considering Yolov2, where w=h=26, c=512 and out_w=out_h=13, out_c=2048. The out_c in function reorg_cpu is calculated as 512/(2*2)=128. And c2 on Line 19 is 0\~128, offset on Line 20 is 0\~3. "offset % stride" and "offset / stride" evaluate both either 0 or 1, denoting the 4 values in the range of one stride.