From 0eb6553122c71d860c57127cc5959a29eb610adc Mon Sep 17 00:00:00 2001 From: SunAhong1993 Date: Mon, 5 Aug 2019 11:45:16 +0800 Subject: [PATCH] fix the shufflechannel and convert.py --- x2paddle/convert.py | 19 +++++++++++-------- .../caffe_custom_layer/shufflechannel.py | 8 +++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/x2paddle/convert.py b/x2paddle/convert.py index 62be5cc..5a94e95 100644 --- a/x2paddle/convert.py +++ b/x2paddle/convert.py @@ -82,17 +82,20 @@ def tf2paddle(model_path, save_dir): def caffe2paddle(proto, weight, save_dir, caffe_proto): - try: - import caffe - version = caffe.__version__ - if version == '1.0.0': - print("caffe == 1.0.0 is required") - return - except: - print("Caffe is not installed.") + if caffe_proto is not None: import os if not os.path.isfile(caffe_proto + 'caffe_pb2.py'): print("The file that resolve caffe is not exist.") + return + else: + try: + import caffe + version = caffe.__version__ + if version != '1.0.0': + print("caffe == 1.0.0 is required") + return + except: + print("Caffe is not installed.") print( "You have 2 options: 1. install caffe 2. compile the caffe.proto" ) diff --git a/x2paddle/op_mapper/caffe_custom_layer/shufflechannel.py b/x2paddle/op_mapper/caffe_custom_layer/shufflechannel.py index f742cfe..c6321f2 100644 --- a/x2paddle/op_mapper/caffe_custom_layer/shufflechannel.py +++ b/x2paddle/op_mapper/caffe_custom_layer/shufflechannel.py @@ -8,7 +8,13 @@ def shufflechannel_shape(input_shape): def shufflechannel_layer(inputs, group=None, input_shape=None, name=None): input = inputs[0] - out = fluid.layers.shuffle_channel(input, group=group, name=name) + 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) return out -- GitLab