How to resize a featureMap(blob) ?

446 views
Skip to first unread message

youngwan lee

unread,
Sep 20, 2017, 9:56:28 PM9/20/17
to Caffe Users
I want to resize  input feature map by factor of 1.5 not 2 without using pooling.

Are there any methods or ways to resize in caffe?

Przemek D

unread,
Sep 21, 2017, 6:19:25 AM9/21/17
to Caffe Users
To the best of my knowledge, the only way to do this is via a custom Python layer.

Downscaling blobs in Caffe is a result of producing an output pixel basing on some area around that pixel (receptive field), and the scaling factor depends on the stride between receptive fields. Existing layers only allow you to shift it by an integer value. No matter if it's pooling, convolution or deconvolution, they all work either in integer steps or on per-element basis. For fractional factor resampling you would need to either shift by a non-integer value (impossible) or use a whole different approach - which in this case is the Python layer. You can do it for example with imresize function found in scipy.misc. Yes this will be a significant slowdown as this will force a copy from GPU to CPU, and you will need to execute the resize twice: the feature map on forward pass and the gradients on backward. But I see no other option.

I do not claim to be a Caffe expert though, so you may want to wait for more answers.

Thomio Watanabe

unread,
Sep 21, 2017, 7:46:05 AM9/21/17
to Caffe Users
Message has been deleted

Przemek D

unread,
Sep 22, 2017, 7:24:08 AM9/22/17
to Caffe Users
A single deconv won't do it for the reason I previously mentioned - transformations based on a shifted receptive field (conv/deconv/pool and the like) can only scale by an integer factor (up or down).
Mind that you can achieve an apparent fractional rescale by picking the right kernel size and padding, but from the point of view of spatial size of the features, this will be equivalent to cropping the input - the scale will not change by a fractional factor.

However, you can do that if you're willing to split the operation into two steps: first upsample by 3 (deconv with kernel 3 stride 3 with constant weight = nearest-neighbor upsampling) then downsample by 2 (average pooling with kernel 2 stride 2 OR conv with grouped bilinear upsampling filter) => you've just got a 1.5x downsample. This will actually scale the features and not just the blob size, which I assumed is what you want to accomplish.

(I removed my previous answer and replaced with this improved one.)
Reply all
Reply to author
Forward
0 new messages