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

caffe2fluid:Move caffe2fluid out (#1470)

上级 80681ed6
......@@ -21,6 +21,7 @@ import reduction
custom_layers = get_registered_layers()
def set_args(f, params, node=None):
""" set args for function 'f' using the parameters in node.layer.parameters
......
......@@ -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"
return input_shape[1]
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
else:
raise Exception,"crop_shape input error"
raise Exception, "crop_shape input error"
return None
def crop_layer(input, name, shape=None, axis=2, offset=None):
""" build a layer of type 'Crop' using fluid
......@@ -46,23 +48,28 @@ def crop_layer(input, name, shape=None, axis=2, offset=None):
output_shape = input[1].shape
input_tensor = input[0]
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
output_shape = shape
input_tensor = input
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:
axis += len(input_shape)
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
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
......
......@@ -18,7 +18,7 @@ def reduction_shape(input_shape, axis=0):
axis += len(input_shape) + 1
assert axis <= len(input_shape), 'invalid axis[%d] error' % (axis)
return input_shape[0:axis]
......@@ -35,27 +35,33 @@ def reduction_layer(input, name, axis=0, operation=1, coeff=1.0):
Returns:
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)
if axis < 0:
axis += input_len + 1
dim = range(input_len)
import paddle.fluid as fluid
if operation == 1: ## operation = SUM
output = fluid.layers.reduce_sum(input, dim=dim[axis:], keep_dim=False, name=name)
elif operation == 2: ## operation = ASUM
if operation == 1: ## operation = SUM
output = fluid.layers.reduce_sum(
input, dim=dim[axis:], keep_dim=False, name=name)
elif operation == 2: ## operation = ASUM
absout = fluid.layers.abs(input)
output = fluid.layers.reduce_sum(absout, dim=dim[axis:], keep_dim=False, name=name)
elif operation == 3: ## operation = SUMSQ
output = fluid.layers.reduce_sum(
absout, dim=dim[axis:], keep_dim=False, name=name)
elif operation == 3: ## operation = SUMSQ
powout = fluid.layers.pow(x=input, factor=2.0)
output = fluid.layers.reduce_sum(powout, 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)
output = fluid.layers.reduce_sum(
powout, 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)
return mulout
register(kind='Reduction', shape=reduction_shape, layer=reduction_layer)
......@@ -338,7 +338,8 @@ class Network(object):
s_w,
ceil_mode,
padding,
name=self.get_unique_output_name(name, 'avg_pool'))
name=self.get_unique_output_name(name, 'avg_pool'),
exclusive=False)
@layer
def sigmoid(self, input, name):
......
......@@ -62,9 +62,11 @@ def shape_identity(node):
def shape_scalar(node):
return make_tensor(1, 1, 1, 1)
def shape_crop(node):
raise KaffeError('crop function had been defined in customer_layers')
def shape_data(node):
if node.output_shape:
# Old-style input specification
......
......@@ -22,7 +22,7 @@ Fluid模型配置和参数文件的工具。
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>`__
- `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模型配置和参数文件的工具。
- [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)
- [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年自主研发的语义匹配框架
- [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)
- [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.
先完成此消息的编辑!
想要评论请 注册