Skip to content

Commit

Permalink
Merge pull request torch#297 from fmassa/conv_assert
Browse files Browse the repository at this point in the history
Assert output size in SpatialConvolutionMM + doc fix
  • Loading branch information
soumith committed Jun 19, 2015
2 parents c293e84 + d4b9c48 commit 3550f31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/convolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ The parameters are the following:
* `dW`: The step of the convolution in the width dimension. Default is `1`.
* `dH`: The step of the convolution in the height dimension. Default is `1`.
* `padW`: The additional zeros added per width to the input planes. Default is `0`, a good number is `(kW-1)/2`.
* `padH`: The additional zeros added per height to the input planes. Default is `0`, a good number is `(kH-1)/2`.
* `padH`: The additional zeros added per height to the input planes. Default is `padW`, a good number is `(kH-1)/2`.

Note that depending of the size of your kernel, several (of the last)
columns or rows of the input image might be lost. It is up to the user to
Expand Down
4 changes: 4 additions & 0 deletions generic/SpatialConvolutionMM.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ static int nn_(SpatialConvolutionMM_updateOutput)(lua_State *L)
outputWidth = (inputWidth + 2*padW - kW) / dW + 1;
outputHeight = (inputHeight + 2*padH - kH) / dH + 1;

if (outputWidth < 1 || outputHeight < 1)
THError("Given input size: (%dx%dx%d). Calculated output size: (%dx%dx%d). Output size is too small",
nInputPlane,inputHeight,inputWidth,nInputPlane,outputHeight,outputWidth);

if(input->nDimension == 3)
{
THTensor_(resize2d)(finput, kW*kH*nInputPlane, outputHeight*outputWidth);
Expand Down

0 comments on commit 3550f31

Please sign in to comment.