提交 fc5c67c4 编写于 作者: C Channingss

support yolov3

上级 fc4d2464
...@@ -2,8 +2,6 @@ import onnx ...@@ -2,8 +2,6 @@ import onnx
import numpy as np import numpy as np
from onnx import onnx_pb, helper from onnx import onnx_pb, helper
MAX_FLOAT = np.asarray([255, 255, 127, 127], dtype=np.uint8).view(np.float32)[0]
def get_old_name(arg, name_prefix=''): def get_old_name(arg, name_prefix=''):
prefix_index = arg.find(name_prefix) prefix_index = arg.find(name_prefix)
...@@ -749,53 +747,36 @@ def yolo_box(op, block): ...@@ -749,53 +747,36 @@ def yolo_box(op, block):
outputs_pred_box_x2_clip = [model_name + "@pred_box_x2_clip"] outputs_pred_box_x2_clip = [model_name + "@pred_box_x2_clip"]
outputs_pred_box_y2_clip = [model_name + "@pred_box_y2_clip"] outputs_pred_box_y2_clip = [model_name + "@pred_box_y2_clip"]
min_const_name = model_name + "@pred_box_min_const"
max_const_name = model_name + "@pred_box_max_const"
min_const = onnx.helper.make_node(
'Constant',
inputs=[],
outputs=[min_const_name],
value=onnx.helper.make_tensor(
name=min_const_name,
data_type=onnx.TensorProto.FLOAT,
dims=(),
vals=[0.0]))
node_list.append(min_const)
max_const = onnx.helper.make_node(
'Constant',
inputs=[],
outputs=[max_const_name],
value=onnx.helper.make_tensor(
name=max_const_name,
data_type=onnx.TensorProto.FLOAT,
dims=(),
vals=[MAX_FLOAT]))
node_list.append(max_const)
node_pred_box_x1_clip = onnx.helper.make_node( node_pred_box_x1_clip = onnx.helper.make_node(
'Clip', 'Clip',
inputs=outputs_pred_box_x1_decode + [min_const_name, max_const_name], inputs=outputs_pred_box_x1_decode,
outputs=outputs_pred_box_x1_clip) outputs=outputs_pred_box_x1_clip,
min=0.0,
max=float(np.inf))
node_list.append(node_pred_box_x1_clip) node_list.append(node_pred_box_x1_clip)
node_pred_box_y1_clip = onnx.helper.make_node( node_pred_box_y1_clip = onnx.helper.make_node(
'Clip', 'Clip',
inputs=outputs_pred_box_y1_decode + [min_const_name, max_const_name], inputs=outputs_pred_box_y1_decode,
outputs=outputs_pred_box_y1_clip) outputs=outputs_pred_box_y1_clip,
min=0.0,
max=float(np.inf))
node_list.append(node_pred_box_y1_clip) node_list.append(node_pred_box_y1_clip)
node_pred_box_x2_clip = onnx.helper.make_node( node_pred_box_x2_clip = onnx.helper.make_node(
'Clip', 'Clip',
inputs=outputs_pred_box_x2_sub_w + [min_const_name, max_const_name], inputs=outputs_pred_box_x2_sub_w,
outputs=outputs_pred_box_x2_clip) outputs=outputs_pred_box_x2_clip,
min=0.0,
max=float(np.inf))
node_list.append(node_pred_box_x2_clip) node_list.append(node_pred_box_x2_clip)
node_pred_box_y2_clip = onnx.helper.make_node( node_pred_box_y2_clip = onnx.helper.make_node(
'Clip', 'Clip',
inputs=outputs_pred_box_y2_sub_h + [min_const_name, max_const_name], inputs=outputs_pred_box_y2_sub_h,
outputs=outputs_pred_box_y2_clip) outputs=outputs_pred_box_y2_clip,
min=0.0,
max=float(np.inf))
node_list.append(node_pred_box_y2_clip) node_list.append(node_pred_box_y2_clip)
outputs_pred_box_x2_res = [model_name + "@box_x2_res"] outputs_pred_box_x2_res = [model_name + "@box_x2_res"]
......
...@@ -675,17 +675,15 @@ class PaddleOpMapper(object): ...@@ -675,17 +675,15 @@ class PaddleOpMapper(object):
if 'OutSize' in input_names and len(op.input('OutSize')) > 0: if 'OutSize' in input_names and len(op.input('OutSize')) > 0:
node = helper.make_node( node = helper.make_node(
'Resize', 'Resize',
inputs=[op.input('X')[0], '', op.input('OutSize')[0]], inputs=[op.input('X')[0], op.input('OutSize')[0]],
outputs=op.output('Out'), outputs=op.output('Out'),
mode='nearest', mode='nearest')
coordinate_transformation_mode=coordinate_transformation_mode)
elif 'Scale' in input_names and len(op.input('Scale')) > 0: elif 'Scale' in input_names and len(op.input('Scale')) > 0:
node = helper.make_node( node = helper.make_node(
'Resize', 'Resize',
inputs=[op.input('X')[0], op.input('Scale')[0]], inputs=[op.input('X')[0], op.input('Scale')[0]],
outputs=op.output('Out'), outputs=op.output('Out'),
mode='nearest', mode='nearest')
coordinate_transformation_mode=coordinate_transformation_mode)
else: else:
out_shape = [op.attr('out_h'), op.attr('out_w')] out_shape = [op.attr('out_h'), op.attr('out_w')]
scale = op.attr('scale') scale = op.attr('scale')
...@@ -698,9 +696,7 @@ class PaddleOpMapper(object): ...@@ -698,9 +696,7 @@ class PaddleOpMapper(object):
'Resize', 'Resize',
inputs=[op.input('X')[0], scale_name], inputs=[op.input('X')[0], scale_name],
outputs=op.output('Out'), outputs=op.output('Out'),
mode='nearest', mode='nearest')
coordinate_transformation_mode=coordinate_transformation_mode
)
return [scale_node, node] return [scale_node, node]
else: else:
raise Exception("Unexpected situation happend") raise Exception("Unexpected situation happend")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册