Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help for calculating convolution output with stride #39

Closed
russellfei opened this issue Nov 13, 2014 · 1 comment
Closed

Need help for calculating convolution output with stride #39

russellfei opened this issue Nov 13, 2014 · 1 comment

Comments

@russellfei
Copy link

The convolution network modules part:

3 :
{
padding : 3
kW : 7
nInputPlane : 8
gradBias : CudaTensor - size: 8
dW : 1
gradWeight : CudaTensor - size: 8x392
output : CudaTensor - size: 1x8x61x61
fgradInput : CudaTensor - size: 61x61
finput : CudaTensor - size: 392x3721
bias : CudaTensor - size: 8
weight : CudaTensor - size: 8x392
nOutputPlane : 8
gradInput : CudaTensor - empty
kH : 7
dH : 1
}
4 :
{
padding : 2
kW : 7
nInputPlane : 8
gradBias : CudaTensor - size: 12
dW : 1
gradWeight : CudaTensor - size: 12x392
output : CudaTensor - size: 1x12x59x59
fgradInput : CudaTensor - size: 59x59
finput : CudaTensor - size: 392x3481
bias : CudaTensor - size: 12
weight : CudaTensor - size: 12x392
nOutputPlane : 12
gradInput : CudaTensor - empty
kH : 7
dH : 1

}

As is listed above, the output size of layer 3 is 8x61x61

The layer 4 is defined as nn.SpatialConvolutionMM(8,12,7,7,1,1,3))

from which we should expected output is

(61+3-7)/1+1 = 58,

however, the module info shows that the output is 12x59x59.

Anyone can help me figure out this?

thx~

@russellfei
Copy link
Author

All right, no one replied. Well, I have got one idea to discriminate the stride and padding mode for nn.SpatialconvolutionMM and nn.SpatialConvolutionCUDA. Keep in mind that SpatialConvolutionMM support stride-mode only in CUDA ( great hint from @soumith ).

To keep short, just list conclusions here:

  1. nn.SpatialConvolutionMM( nInputPlane, nOutPlane, kW, kH, dW, dH, padding ) computes output size according to

out_W = ( inWidth + 2*padding - kW ) / dW + 1

  1. nn.SpatialConvolutionCUDA( nInputPlane, nOutPlane, kW, kH, dW, dH, padding, partialSum ) use the equation below, I have no idea about partialSum, how to use it? @_@

out_W = ( inWidth + padding - kW ) / dW + 1

  1. Thanks to @soumith , the SpatialConvolutionMM uses BDHW layout while SpatialConvolutionCUDA uses 'DHWB' layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant