提交 19b08cfd 编写于 作者: W walloollaw 提交者: qingqing01

caffe2fluid:Move caffe2fluid out (#1470)

上级 80681ed6
...@@ -21,6 +21,7 @@ import reduction ...@@ -21,6 +21,7 @@ import reduction
custom_layers = get_registered_layers() custom_layers = get_registered_layers()
def set_args(f, params, node=None): def set_args(f, params, node=None):
""" set args for function 'f' using the parameters in node.layer.parameters """ set args for function 'f' using the parameters in node.layer.parameters
......
...@@ -18,12 +18,14 @@ def crop_shape(input_shape, shape=None): ...@@ -18,12 +18,14 @@ def crop_shape(input_shape, shape=None):
assert len(input_shape) == 2, "the number of crop's inputs must be 2" assert len(input_shape) == 2, "the number of crop's inputs must be 2"
return input_shape[1] return input_shape[1]
elif not shape is None: elif not shape is None:
assert len(shape) == len(input_shape.shape), "input_shape is diff with output_shape" assert len(shape) == len(
input_shape.shape), "input_shape is diff with output_shape"
return shape return shape
else: else:
raise Exception,"crop_shape input error" raise Exception, "crop_shape input error"
return None return None
def crop_layer(input, name, shape=None, axis=2, offset=None): def crop_layer(input, name, shape=None, axis=2, offset=None):
""" build a layer of type 'Crop' using fluid """ build a layer of type 'Crop' using fluid
...@@ -46,23 +48,28 @@ def crop_layer(input, name, shape=None, axis=2, offset=None): ...@@ -46,23 +48,28 @@ def crop_layer(input, name, shape=None, axis=2, offset=None):
output_shape = input[1].shape output_shape = input[1].shape
input_tensor = input[0] input_tensor = input[0]
elif not shape is None: elif not shape is None:
assert len(shape) == len(input.shape), "input_shape is diff with output_shape" assert len(shape) == len(
input.shape), "input_shape is diff with output_shape"
input_shape = input.shape input_shape = input.shape
output_shape = shape output_shape = shape
input_tensor = input input_tensor = input
else: else:
raise Exception,"crop_layer input error" raise Exception, "crop_layer input error"
assert len(output_shape) == len(input_shape), "input_shape is diff with output_shape" assert len(output_shape) == len(
input_shape), "input_shape is diff with output_shape"
if axis < 0: if axis < 0:
axis += len(input_shape) axis += len(input_shape)
if offset is not None: if offset is not None:
assert (len(input_shape) - axis) == len(offset), "invalid offset[%s] in crop layer" % (str(offset)) assert (len(input_shape) - axis
) == len(offset), "invalid offset[%s] in crop layer" % (
str(offset))
offset = [0] * axis + offset offset = [0] * axis + offset
import paddle.fluid as fluid import paddle.fluid as fluid
output = fluid.layers.crop(input_tensor, shape=output_shape, offsets=offset, name=name) output = fluid.layers.crop(
input_tensor, shape=output_shape, offsets=offset, name=name)
return output return output
......
...@@ -18,7 +18,7 @@ def reduction_shape(input_shape, axis=0): ...@@ -18,7 +18,7 @@ def reduction_shape(input_shape, axis=0):
axis += len(input_shape) + 1 axis += len(input_shape) + 1
assert axis <= len(input_shape), 'invalid axis[%d] error' % (axis) assert axis <= len(input_shape), 'invalid axis[%d] error' % (axis)
return input_shape[0:axis] return input_shape[0:axis]
...@@ -35,27 +35,33 @@ def reduction_layer(input, name, axis=0, operation=1, coeff=1.0): ...@@ -35,27 +35,33 @@ def reduction_layer(input, name, axis=0, operation=1, coeff=1.0):
Returns: Returns:
output (variable): output variable for this layer output (variable): output variable for this layer
""" """
assert operation >= 1 and operation <= 4, "reduction reduction [%s] error" % (operation) assert operation >= 1 and operation <= 4, "reduction reduction [%s] error" % (
operation)
input_len = len(input.shape) input_len = len(input.shape)
if axis < 0: if axis < 0:
axis += input_len + 1 axis += input_len + 1
dim = range(input_len) dim = range(input_len)
import paddle.fluid as fluid import paddle.fluid as fluid
if operation == 1: ## operation = SUM if operation == 1: ## operation = SUM
output = fluid.layers.reduce_sum(input, dim=dim[axis:], keep_dim=False, name=name) output = fluid.layers.reduce_sum(
elif operation == 2: ## operation = ASUM input, dim=dim[axis:], keep_dim=False, name=name)
elif operation == 2: ## operation = ASUM
absout = fluid.layers.abs(input) absout = fluid.layers.abs(input)
output = fluid.layers.reduce_sum(absout, dim=dim[axis:], keep_dim=False, name=name) output = fluid.layers.reduce_sum(
elif operation == 3: ## operation = SUMSQ absout, dim=dim[axis:], keep_dim=False, name=name)
elif operation == 3: ## operation = SUMSQ
powout = fluid.layers.pow(x=input, factor=2.0) powout = fluid.layers.pow(x=input, factor=2.0)
output = fluid.layers.reduce_sum(powout, dim=dim[axis:], keep_dim=False, name=name) output = fluid.layers.reduce_sum(
else: ## operation = MEAN powout, dim=dim[axis:], keep_dim=False, name=name)
output = fluid.layers.reduce_mean(input, dim=dim[axis:], keep_dim=False, name=name) else: ## operation = MEAN
output = fluid.layers.reduce_mean(
input, dim=dim[axis:], keep_dim=False, name=name)
mulout = fluid.layers.scale(x=output, scale=coeff) mulout = fluid.layers.scale(x=output, scale=coeff)
return mulout return mulout
register(kind='Reduction', shape=reduction_shape, layer=reduction_layer) register(kind='Reduction', shape=reduction_shape, layer=reduction_layer)
...@@ -338,7 +338,8 @@ class Network(object): ...@@ -338,7 +338,8 @@ class Network(object):
s_w, s_w,
ceil_mode, ceil_mode,
padding, padding,
name=self.get_unique_output_name(name, 'avg_pool')) name=self.get_unique_output_name(name, 'avg_pool'),
exclusive=False)
@layer @layer
def sigmoid(self, input, name): def sigmoid(self, input, name):
......
...@@ -62,9 +62,11 @@ def shape_identity(node): ...@@ -62,9 +62,11 @@ def shape_identity(node):
def shape_scalar(node): def shape_scalar(node):
return make_tensor(1, 1, 1, 1) return make_tensor(1, 1, 1, 1)
def shape_crop(node): def shape_crop(node):
raise KaffeError('crop function had been defined in customer_layers') raise KaffeError('crop function had been defined in customer_layers')
def shape_data(node): def shape_data(node):
if node.output_shape: if node.output_shape:
# Old-style input specification # Old-style input specification
......
...@@ -22,7 +22,7 @@ Fluid模型配置和参数文件的工具。 ...@@ -22,7 +22,7 @@ Fluid模型配置和参数文件的工具。
Network <https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models>`__ Network <https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models>`__
- `SE-ResNeXt <https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models>`__ - `SE-ResNeXt <https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models>`__
- `Caffe模型转换为Paddle - `Caffe模型转换为Paddle
Fluid配置和模型文件工具 <https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/caffe2fluid>`__ Fluid配置和模型文件工具 <https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/caffe2fluid>`__
目标检测 目标检测
-------- --------
......
...@@ -17,7 +17,7 @@ Fluid模型配置和参数文件的工具。 ...@@ -17,7 +17,7 @@ Fluid模型配置和参数文件的工具。
- [MobileNet](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models) - [MobileNet](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models)
- [Dual Path Network](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models) - [Dual Path Network](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models)
- [SE-ResNeXt](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models) - [SE-ResNeXt](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/models)
- [Caffe模型转换为Paddle Fluid配置和模型文件工具](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/image_classification/caffe2fluid) - [Caffe模型转换为Paddle Fluid配置和模型文件工具](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/caffe2fluid)
目标检测 目标检测
-------- --------
...@@ -167,4 +167,3 @@ SimNet是百度自然语言处理部于2013年自主研发的语义匹配框架 ...@@ -167,4 +167,3 @@ SimNet是百度自然语言处理部于2013年自主研发的语义匹配框架
- [SequenceSemanticRetrieval](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleRec/ssr) - [SequenceSemanticRetrieval](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleRec/ssr)
- [DeepCTR](https://github.com/PaddlePaddle/models/blob/develop/fluid/PaddleRec/ctr/README.cn.md) - [DeepCTR](https://github.com/PaddlePaddle/models/blob/develop/fluid/PaddleRec/ctr/README.cn.md)
- [Multiview-Simnet](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleRec/multiview_simnet) - [Multiview-Simnet](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleRec/multiview_simnet)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册