diff --git a/x2paddle/op_mapper/caffe_custom_layer/shufflechannel.py b/x2paddle/op_mapper/caffe_custom_layer/shufflechannel.py index bc56c2239fee4f6c368921bc1297c1a2eb1c07f6..191f23c459066ccc731e2afa9770e2046a197591 100644 --- a/x2paddle/op_mapper/caffe_custom_layer/shufflechannel.py +++ b/x2paddle/op_mapper/caffe_custom_layer/shufflechannel.py @@ -8,13 +8,7 @@ def shufflechannel_shape(input_shape): def shufflechannel_layer(inputs, group=None, input_shape=None, name=None): input = inputs[0] - c_fm = fluid.layers.split(input, num_or_sections=input_shape[0][1], dim=1) - size = int(input_shape[0][1] / group) - new_c_fm = [] - for i in range(size): - for j in range(group): - new_c_fm.append(c_fm[j * size + i]) - out = fluid.layers.concat(new_c_fm, axis=1) + out = fluid.layers.shuffle_channel(x=input, group=group) return out diff --git a/x2paddle/op_mapper/caffe_op_mapper.py b/x2paddle/op_mapper/caffe_op_mapper.py index 5d25f4a7c67e13d528d0d387144e1e6e56b60ff5..abdbbaef11a45af55657a15d1c2b2536383df8f5 100644 --- a/x2paddle/op_mapper/caffe_op_mapper.py +++ b/x2paddle/op_mapper/caffe_op_mapper.py @@ -450,35 +450,19 @@ class CaffeOpMapper(OpMapper): slice_dim = params.slice_dim if slice_dim != 1 and axis == 1: axis = slice_dim - points = list(params.slice_point) - - if len(points) == 0: - dims = node.input_shape[0][axis] - assert dims % top_len == 0, "the parameter of Slice is wrong" - part = dims / top_len - t = part - while t < dims: - points.append(int(t)) - t += part - maxint32 = 2147483647 - points = [0] + points - points.append(maxint32) - i = 0 - node.fluid_code.add_note('{} = []'.format(node.layer_name)) - for i in range(len(points)): - attr = { - 'axes': [axis], - 'starts': [points[i]], - 'ends': [points[i + 1]] - } - node.fluid_code.add_layer("slice", - inputs=input, - output=node.layer_name + '_' + str(i), - param_attr=attr) - node.fluid_code.add_note('{}.append({})'.format( - node.layer_name, node.layer_name + '_' + str(i))) - if i == len(points) - 2: - break + output_shape = node.output_shape + sections_list = [] + for s in output_shape: + sections_list.append(s[axis]) + attr = { + 'num_or_sections': sections_list, + 'dim': axis, + 'name': string(node.layer_name) + } + node.fluid_code.add_layer("split", + inputs=input, + output=node.layer_name, + param_attr=attr) def Concat(self, node): assert len(