未验证 提交 9277f0bc 编写于 作者: W WJJ1995 提交者: GitHub

Fix caffe bug && Add onnx 3d interpolate support (#611)

* fix caffe kernel_size=0 bug

* add onnx 3d interpolate support
上级 66b2a048
......@@ -62,15 +62,15 @@ def _get_kernel_parameters(kind, params):
"Convolution", "Pooling", "Deconvolution", "ConvolutionDepthwise"
]
[k_h, k_w] = [1, 1]
if isinstance(params.kernel_size, numbers.Number):
if params.kernel_h > 0 or params.kernel_w > 0:
k_h = params.kernel_h
k_w = params.kernel_w
elif isinstance(params.kernel_size, numbers.Number):
[k_h, k_w] = [params.kernel_size] * 2
elif len(params.kernel_size) > 0:
k_h = params.kernel_h if params.kernel_h > 0 else params.kernel_size[0]
k_w = params.kernel_w if params.kernel_w > 0 else params.kernel_size[
len(params.kernel_size) - 1]
elif params.kernel_h > 0 or params.kernel_w > 0:
k_h = params.kernel_h
k_w = params.kernel_w
[s_h, s_w] = [1, 1]
if isinstance(params.stride, numbers.Number):
[s_h, s_w] = [params.stride] * 2
......
......@@ -309,6 +309,51 @@ class OpSet9():
elif len(node.layer.input) == 4:
# opset 11
val_sizes = self.graph.get_input_node(node, idx=3, copy=True)
val_x_shape = val_x.out_shapes[0]
if len(val_x_shape) == 3:
var_n, var_hw = val_sizes.name + '_n', val_sizes.name + '_hw'
self.paddle_graph.add_layer(
'paddle.split',
inputs={"x": val_sizes.name},
outputs=[var_n, var_hw],
num_or_sections=[1, 2],
axis=0)
self.paddle_graph.add_layer(
"paddle.cast",
inputs={"x": var_hw},
outputs=[var_hw],
dtype=string('int32'))
inputs['size'] = var_hw
attrs = {
"align_corners": False,
"mode": string(node.get_attr('mode', 'nearest'))
}
mode = node.get_attr('mode', 'nearest')
if mode == "linear":
attrs["mode"] = string("bilinear")
if node.get_attr('coordinate_transformation_mode',
'half_pixel') == 'pytorch_half_pixel':
attrs["align_corners"] = False
attrs["align_mode"] = 0
if node.get_attr('coordinate_transformation_mode',
'half_pixel') == 'align_corners':
attrs["align_corners"] = True
self.paddle_graph.add_layer(
'paddle.unsqueeze',
inputs={"x": val_x.name},
outputs=[val_x.name],
axis=0)
self.paddle_graph.add_layer(
kernel="paddle.nn.functional.interpolate",
inputs=inputs,
outputs=[node.name],
**attrs)
self.paddle_graph.add_layer(
'paddle.squeeze',
inputs={"x": node.name},
outputs=[node.name],
axis=0)
else:
var_nc, var_hw = val_sizes.name + '_nc', val_sizes.name + '_hw'
self.paddle_graph.add_layer(
'paddle.split',
......@@ -333,6 +378,9 @@ class OpSet9():
'half_pixel') == 'pytorch_half_pixel':
attrs["align_corners"] = False
attrs["align_mode"] = 0
if node.get_attr('coordinate_transformation_mode',
'half_pixel') == 'align_corners':
attrs["align_corners"] = True
self.paddle_graph.add_layer(
kernel="paddle.nn.functional.interpolate",
inputs=inputs,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册