How can I use Interpolate without learnable parameters mxnet

I am trying to interpolate x in the hybrid_forward().

I noticed there is a UpSampling() function, but I found it’s function has learnable prameters, which is not I expected.

F.BilinearResize2D() can also upsample, but it needs width and height. I need to upsample with a scale=2 and I can get height and width during hybrid_forward() in HybridBlock.

Is there a way to solve my question.
Does mxnet have some methods similar to Pytorch torch.nn.functional.interpolate

Thank you

Hi @Alpha,
your question is similar to How to upsamle a layer into the shape of another layer in the symbol api?.
I think if you use F.UpSampling() without a num_filter argument, then it shouldn’t have parameters:

F.UpSampling(x, scale=self.scale, sample_type='bilinear')

You can verify this using the model summary:

mx.viz.print_summary(
   symbol,
   shape={'data':(1, input_shape[0], input_shape[1], input_shape[2])},
)
_
Layer (type)                                        Output Shape            Param #     Previous Layer                  
========================================================================================================================
...
________________________________________________________________________________________________________________________
value_conv0(Convolution)                            4x8x8                   25600       bc_res_block12_add              
________________________________________________________________________________________________________________________
value_bn0(BatchNorm)                                4x8x8                   8           value_conv0                     
________________________________________________________________________________________________________________________
value_act0(Activation)                              4x8x8                   0           value_bn0                       
________________________________________________________________________________________________________________________
up(UpSampling)                                      4x16x16                 0           value_act0                      
________________________________________________________________________________________________________________________
value_flatten0(Flatten)                             1024                    0           up                              
______________________________________________________________________________________________________________________
...                                 

Greetings,
~QueensGambit

1 Like

@Alpha, there is also this operator that you might find useful if you need to resize to a fixed size https://mxnet.apache.org/api/python/docs/api/ndarray/contrib/index.html#mxnet.ndarray.contrib.BilinearResize2D

1 Like