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