diff --git a/x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/multiclass_nms.py b/x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/multiclass_nms.py index fa578cc65d5c36aec5e006394c38e4a3f3f469b6..b6bb8cce57fc06bde20ce1c0faa68cb9bd615cb0 100644 --- a/x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/multiclass_nms.py +++ b/x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/multiclass_nms.py @@ -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"] diff --git a/x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/yolo_box.py b/x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/yolo_box.py index 5e674d5217693227d4eec33b58f7d252296947f1..919022167b235899422e9bb8079e03ada683a8c5 100644 --- a/x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/yolo_box.py +++ b/x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/yolo_box.py @@ -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( diff --git a/x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/multiclass_nms.py b/x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/multiclass_nms.py index 58d8e0c9d1c9e780b62cfba578973512e1214ba8..65430bb159bb4698b62fa9bda6b572062b49b6fc 100644 --- a/x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/multiclass_nms.py +++ b/x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/multiclass_nms.py @@ -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"] diff --git a/x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/yolo_box.py b/x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/yolo_box.py index 63f9a9d4e99f0e478609879edc550da0076e0c5b..a8c3a8c889a9e5cf4f8c8dfe12fdf99656187628 100644 --- a/x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/yolo_box.py +++ b/x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/yolo_box.py @@ -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]