From 8b21d123932f618a6f5c7d60e7e6408fcf43aa96 Mon Sep 17 00:00:00 2001 From: SunAhong1993 Date: Wed, 27 Nov 2019 21:47:30 +0800 Subject: [PATCH] fix the reshape problem --- .../caffe_custom_layer/detectionoutput.py | 5 +++-- x2paddle/op_mapper/caffe_shape.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/x2paddle/op_mapper/caffe_custom_layer/detectionoutput.py b/x2paddle/op_mapper/caffe_custom_layer/detectionoutput.py index 173f5f3..6411833 100644 --- a/x2paddle/op_mapper/caffe_custom_layer/detectionoutput.py +++ b/x2paddle/op_mapper/caffe_custom_layer/detectionoutput.py @@ -12,6 +12,7 @@ def detectionoutput_layer(inputs, share_location=True, keep_top_k=100, confidence_threshold=0.1, + num_classes=2, input_shape=None, name=None): nms_param_str = nms_param @@ -36,9 +37,9 @@ def detectionoutput_layer(inputs, pb = fluid.layers.reshape(x=pb, shape=[-1, 4]) pbv = fluid.layers.reshape(x=pbv, shape=[-1, 4]) mbox_loc = inputs[0] - mbox_loc = fluid.layers.reshape(x=mbox_loc, shape=[-1, pb.shape[0], 4]) + mbox_loc = fluid.layers.reshape(x=mbox_loc, shape=[0, -1, 4]) mbox_conf_flatten = fluid.layers.reshape(x=mbox_conf_flatten, - shape=[0, pb.shape[0], -1]) + shape=[0, -1, num_classes]) default = {"nms_threshold": 0.3, "top_k": 10, "eta": 1.0} fields = ['eta', 'top_k', 'nms_threshold'] diff --git a/x2paddle/op_mapper/caffe_shape.py b/x2paddle/op_mapper/caffe_shape.py index 608a9d2..b1b18e4 100644 --- a/x2paddle/op_mapper/caffe_shape.py +++ b/x2paddle/op_mapper/caffe_shape.py @@ -293,15 +293,12 @@ def shape_reshape(layer, input_shape): explicit_count *= count(l) for i in range(len(copy_axes)): explicit_count *= outshape[start_axis + copy_axes[i]] - assert input_count % explicit_count == 0, "[Reshape]botom count[%d] "\ - "must be divisible by product of the specified dimensions[%d] "\ - % (input_count, explicit_count) - outshape[start_axis + inferred_axis] = int(input_count / explicit_count) + outshape[start_axis + inferred_axis] = -1 + outshape[0] = 0 + else: + outshape[0] = -1 output_count = count(outshape) - assert output_count == input_count, "[Reshape]output count[%d] must match input count[%d]" % ( - output_count, input_count) - outshape[0] = -1 return [outshape] @@ -345,9 +342,10 @@ def shape_flatten(layer, input_shape): output_shape = inshape[0:start_axis] if len(inshape[start_axis:end_axis]) != 0: flat_sz = reduce(lambda a, b: a * b, inshape[start_axis:end_axis]) + flat_sz = -1 + output_shape[0] = 0 output_shape += [flat_sz] output_shape += inshape[end_axis:len(inshape)] - output_shape[0] = -1 return [output_shape] -- GitLab