torch / demos

Demos and tutorials around Torch7.
355 stars 301 forks source link

Convolution layers lose col/row: train-a-digit-classifier/train-on-mnist.lua #45

Closed tommy-u closed 8 years ago

tommy-u commented 8 years ago

I believe the first max pooling layer destroys 1 row and 1 col of data. The input was 32x32 tensor, and after applying SpatialConvolutionMM(1, 32, 5, 5) we recovered a 32x28x28 tensor. Running SpatialMaxPooling(3, 3, 3, 3) should miss the last row and column of the 28x28 feature maps.

I tried to fix this by changing the pooling step to SpatialMaxPooling(3, 3, 3, 3, 2, 2 ), but recovered the error: ...lua/5.1/nn/THNN.lua:109: bad argument # 2 to 'v' (pad should be smaller than half of kernel size at /tmp/luarocks_nn-scm-1-2785 /nn/lib/THNN/generic/SpatialMaxPooling.c:108)

Can this be fixed simply by padding the pooling step? There's a similar loss of a row and col in the 2nd pooling step in this file.

soumith commented 8 years ago

you should (3,3,3,3,1,1). the effective padding is 2 pixels. 1 on the left and 1 on the right

tommy-u commented 8 years ago

Thank you.