提交 9d3a4835 编写于 作者: C Channingss

update user prompt

上级 1472f8d5
......@@ -19,7 +19,7 @@ import numpy as np
import paddle.fluid.core as core
import paddle.fluid as fluid
import onnx
import warnings
import logging
from onnx import helper, onnx_pb
......@@ -42,9 +42,9 @@ def multiclass_nms(op, block):
background = attrs['background_label']
normalized = attrs['normalized']
if normalized == False:
warnings.warn(
'The parameter normalized of multiclass_nms OP of Paddle is False, which has diff with ONNX. \
Please set normalized=True in multiclass_nms of Paddle')
logging.warn(
"The parameter normalized of multiclass_nms OP of Paddle is False, which has diff with ONNX." \
" Please set normalized=True in multiclass_nms of Paddle, see doc Q4 in https://github.com/PaddlePaddle/X2Paddle/blob/develop/FAQ.md")
#convert the paddle attribute to onnx tensor
name_score_threshold = [outputs['Out'][0] + "@score_threshold"]
......
......@@ -15,21 +15,9 @@
import onnx
import numpy as np
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=''):
prefix_index = arg.find(name_prefix)
if prefix_index != -1:
last_prefix = arg[len(name_prefix):]
else:
last_prefix = arg
idx = last_prefix.find('@')
if idx != -1:
last_prefix = last_prefix[:idx]
return name_prefix + last_prefix
from x2paddle.op_mapper.paddle2onnx.opset9.paddle_custom_layer.yolo_box import is_static_shape
from x2paddle.op_mapper.paddle2onnx.opset9.paddle_custom_layer.yolo_box import get_old_name
from x2paddle.op_mapper.paddle2onnx.opset9.paddle_custom_layer.yolo_box import MAX_FLOAT32
def yolo_box(op, block):
......@@ -44,6 +32,7 @@ def yolo_box(op, block):
attrs[name] = op.attr(name)
model_name = outputs['Boxes'][0]
input_shape = block.vars[get_old_name(inputs['X'][0])].shape
is_static_shape(input_shape)
image_size = inputs['ImgSize']
input_height = input_shape[2]
input_width = input_shape[3]
......@@ -785,7 +774,7 @@ def yolo_box(op, block):
name=max_const_name,
data_type=onnx.TensorProto.FLOAT,
dims=(),
vals=[MAX_FLOAT]))
vals=[MAX_FLOAT32]))
node_list.append(max_const)
node_pred_box_x1_clip = onnx.helper.make_node(
......
......@@ -19,7 +19,7 @@ import numpy as np
import paddle.fluid.core as core
import paddle.fluid as fluid
import onnx
import warnings
import logging
from onnx import helper, onnx_pb
......@@ -42,9 +42,9 @@ def multiclass_nms(op, block):
background = attrs['background_label']
normalized = attrs['normalized']
if normalized == False:
warnings.warn(
'The parameter normalized of multiclass_nms OP of Paddle is False, which has diff with ONNX. \
Please set normalized=True in multiclass_nms of Paddle')
logging.warn(
"The parameter normalized of multiclass_nms OP of Paddle is False, which has diff with ONNX." \
" Please set normalized=True in multiclass_nms of Paddle, see doc Q4 in https://github.com/PaddlePaddle/X2Paddle/blob/develop/FAQ.md")
#convert the paddle attribute to onnx tensor
name_score_threshold = [outputs['Out'][0] + "@score_threshold"]
......
......@@ -33,6 +33,13 @@ def get_old_name(arg, name_prefix=''):
return name_prefix + last_prefix
def is_static_shape(shape):
if len(shape) > 1 and shape.count(-1) > 1:
raise Exception(
"Converting this model to ONNX need with static input shape, please converting with --fixed_input_shape [H,W]."
)
def yolo_box(op, block):
inputs = dict()
outputs = dict()
......@@ -45,6 +52,7 @@ def yolo_box(op, block):
attrs[name] = op.attr(name)
model_name = outputs['Boxes'][0]
input_shape = block.vars[get_old_name(inputs['X'][0])].shape
is_static_shape(input_shape)
image_size = inputs['ImgSize']
input_height = input_shape[2]
input_width = input_shape[3]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册