   long inputHeight  = input->size[1];
   long inputWidth   = input->size[2];
   long batchSize    = input->size[3];
-  long outputHeight = (inputHeight - kH) / dH + 1;
-  long outputWidth  = (inputWidth - kW) / dW + 1;
+  long outputHeight = (padding + inputHeight - kH) / dH + 1;
+  long outputWidth  = (padding + inputWidth - kW) / dW + 1;
 
   // resize gradInput
   THCudaTensor_resize4d(gradInput, nInputPlane, inputHeight, inputWidth, batchSize);

  
  int dW = luaT_getfieldcheckint(L, 1, "dW");
  int dH = luaT_getfieldcheckint(L, 1, "dH");
  float scale = luaL_optnumber(L, 4, 1);

  long nOutputPlane = gradWeight->size[3];

  THCudaTensor *input = (THCudaTensor*)luaT_checkudata(L, 2, "torch.CudaTensor");
  int dW = luaT_getfieldcheckint(L, 1, "dW");
  int dH = luaT_getfieldcheckint(L, 1, "dH");
  int padding = luaT_getfieldcheckint(L, 1, "padding");

  THCudaTensor *weight = (THCudaTensor*)luaT_getfieldcheckudata(L, 1, "weight", "torch.CudaTensor");
  THCudaTensor *output = (THCudaTensor*)luaT_getfieldcheckudata(L, 1, "output", "torch.CudaTensor");
