How to make two different sizes of feature map have the same size with bigger size?


First feature map is 150x150, I use convolution with stride=2, and then deconvolution with scale=2, the feature map size is 148x148. How can I make 148x148 be 150x150? And then I use mx.symbol.Crop, in, after executing self.forward(), there are error in self.update(). The error is the following :

/home/travis/build/dmlc/mxnet-distro/mxnet-build/dmlc-core/include/dmlc/logging.h:308: [11:17:01] src/operator/./crop-inl.h:126: Check failed: data_shape[2] >= out_shape[2] (148 vs. 150) data_shape’height should be larger than that of out_shape

Any advice will be appreciated. Thank you very much!


Try to add padding to your convolution:
see padding parameter.

In your case, try padding=(1,1).

If that doesn’t work, please post a minimally reproducible example and I will try to help you further.


Hi, according to the documentation the new dimensions are related with the old dimensions with the following formula:

out_height = floor((height+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0])+1
out_width = floor((width+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1])+1

If you fix some of the parameters, and demand out_height==height=h (same for width) you can evaluate the rest parameter values so as sto have padding = ‘SAME’. Solving for padding, p, (for ODD kernels!):

p = (1-d-h+d*k+h*s)/2

where p: padding, d: dilation rate, h:height, k:kernel size. For example, for dilation = 1, and stride = 2, and kernel=3, we get p=(3+h)/2. Same rule holds for transpose convolution as well (deconvolution). Therefore, select some of the p,k,d,s and solve for the other according to the input = output you have.


thanks for your advice. For my input images, the sizes are different, so I am sure how much I need add padding. For my solution, I dilate feature map to a constant size that is estimated to be larger than the size I need. And then I crop the dilated feature map to fit the size of a base feature map.


Thanks for your reply. I also see the equation from the document. My solution is to dilate feature map to a big size, and crop it to the size of a base feature map.