TypeError: upsample_bilinear2d() got an unexpected keyword argument 'align_corners' (occurred when translating upsample_bilinear2d)
lizhen2017 opened this issue · 3 comments
My pytorch version is 0.4.0; I know this is caused by the vesion of onnx and pytorch, how about your upsample.
Bilinear upsample operation in pytorch can not be perfectly reimplemented in caffe, so right now only nearest upsample is supported. @lizhen2017
@YukiNagato I solved this problem by edit pytorch source code torch/onnx/symbolic.py
I add a parameter for this function :align_corners
def upsample_bilinear2d(g, input, output_size, align_corners):
if align_corners:
return _unimplemented("upsample_bilinear2d", "align_corners == True")
w_scale = float(output_size[-1]) / input.type().sizes()[-1]
h_scale = float(output_size[-2]) / input.type().sizes()[-2]
return g.op("Upsample", input, width_scale_f=w_scale,
height_scale_f=h_scale, mode_s="bilinear")
and modify _operators.py
if mode=="bilinear":
layer = myf("Deconvolution", node_name, [input_name], [output_name],
convolution_param=dict(
num_output=channels,
kernel_size=2 * factor - factor % 2,
stride=factor,
pad=pad,
group=channels,
bias_term=False,
weight_filler=dict(type="bilinear")
)
The program can run normally.
Above all, I referred to the source code for pytorch 0.4.1
Yes, but it should be noted that Deconvolution with bilinear filter is not equal to pytorch's upsample_bilinear2d. If you really need bilinear upsample, you can use Interp operation instead (https://github.com/hszhao/PSPNet/blob/master/src/caffe/util/interp.cpp). It is equal to upsample_bilinear2d with align_corners=True. Howerver, i haven't find any caffe code equal to upsample_bilinear2d with align_corners=False.