提交 05dfbab2 编写于 作者: 李寅

Make converter compitable with caffe of old version

上级 1d0f9cc1
...@@ -374,7 +374,9 @@ class CaffeConverter(base_converter.ConverterInterface): ...@@ -374,7 +374,9 @@ class CaffeConverter(base_converter.ConverterInterface):
if len(caffe_op.blobs) == 2: if len(caffe_op.blobs) == 2:
bias_tensor_name = op.name + '_bias' bias_tensor_name = op.name + '_bias'
bias_data = caffe_op.blobs[1] bias_data = caffe_op.blobs[1]
self.add_tensor(bias_tensor_name, bias_data.shape, # caffe of old version has 4-dimension bias, so reshape it
# to single dimension
self.add_tensor(bias_tensor_name, bias_data.reshape(-1).shape,
mace_pb2.DT_FLOAT, mace_pb2.DT_FLOAT,
bias_data) bias_data)
op.input.extend([bias_tensor_name]) op.input.extend([bias_tensor_name])
...@@ -407,7 +409,7 @@ class CaffeConverter(base_converter.ConverterInterface): ...@@ -407,7 +409,7 @@ class CaffeConverter(base_converter.ConverterInterface):
if caffe_op.type == 'PReLU': if caffe_op.type == 'PReLU':
alpha_tensor_name = caffe_op.name + '_alpha' alpha_tensor_name = caffe_op.name + '_alpha'
alpha_data = caffe_op.blobs[0] alpha_data = caffe_op.blobs[0]
self.add_tensor(alpha_tensor_name, alpha_data.shape, self.add_tensor(alpha_tensor_name, alpha_data.reshape(-1).shape,
mace_pb2.DT_FLOAT, alpha_data) mace_pb2.DT_FLOAT, alpha_data)
op.input.extend([alpha_tensor_name]) op.input.extend([alpha_tensor_name])
...@@ -437,10 +439,10 @@ class CaffeConverter(base_converter.ConverterInterface): ...@@ -437,10 +439,10 @@ class CaffeConverter(base_converter.ConverterInterface):
offset_value = ((-mean_value * scale_value) + beta_value).reshape(-1) offset_value = ((-mean_value * scale_value) + beta_value).reshape(-1)
input_names = [op.name + '_scale', op.name + '_offset'] input_names = [op.name + '_scale', op.name + '_offset']
self.add_tensor(input_names[0], scale_value.shape, mace_pb2.DT_FLOAT, self.add_tensor(input_names[0], scale_value.reshape(-1).shape,
scale_value) mace_pb2.DT_FLOAT, scale_value)
self.add_tensor(input_names[1], offset_value.shape, mace_pb2.DT_FLOAT, self.add_tensor(input_names[1], offset_value.reshape(-1).shape,
offset_value) mace_pb2.DT_FLOAT, offset_value)
op.input.extend([name for name in input_names]) op.input.extend([name for name in input_names])
op.output[:] = scale_op.layer.top[:] op.output[:] = scale_op.layer.top[:]
...@@ -508,7 +510,7 @@ class CaffeConverter(base_converter.ConverterInterface): ...@@ -508,7 +510,7 @@ class CaffeConverter(base_converter.ConverterInterface):
if len(caffe_op.blobs) == 2: if len(caffe_op.blobs) == 2:
bias_tensor_name = op.name + '_bias' bias_tensor_name = op.name + '_bias'
bias_data = caffe_op.blobs[1] bias_data = caffe_op.blobs[1]
self.add_tensor(bias_tensor_name, bias_data.shape, self.add_tensor(bias_tensor_name, bias_data.reshape(-1).shape,
mace_pb2.DT_FLOAT, mace_pb2.DT_FLOAT,
bias_data) bias_data)
op.input.extend([bias_tensor_name]) op.input.extend([bias_tensor_name])
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册