InnerProduct.md 2.0 KB
Newer Older
S
sunyanfang01 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
## InnerProduct
### [InnerProduct](http://caffe.berkeleyvision.org/tutorial/layers/innerproduct.html)
```
layer{
    name: "fc"
    type: "InnerProduct"
    bottom: "data"
    top: "fc"
    #卷积核的局部学习率和权值衰减因子
    param{
	lr_mult: 1
	decay_mult: 1
    }
    #偏置项的局部学习率和权值衰减因子
    param{
	lr_mult: 2
	decay_mult: 0
    }
    InnerProduct{
	num_output: 20	#必填项
	bias_term: True
	weight_filler {
	    type: "gaussian"
	    value: 0.01
	}
	bias_filler {
	    type: "constant"
	    value: 0
	}
    }
}
```


### [paddle.fluid.layers.fc](http://paddlepaddle.org/documentation/docs/zh/1.3/api_cn/layers_cn.html#permalink-71-fc)
```python
paddle.fluid.layers.fc(
    input,
    size,
    num_flatten_dims=1,
    param_attr=None,
    bias_attr=None,
    act=None,
    is_test=False,
    name=None
)
```  

### 功能差异
J
Jason 已提交
50
#### 参数初始化
J
Jason 已提交
51 52
Caffe:Layer定义中共有两个结构体`param`用于设置局部学习率和权值衰减因子,其中第一个用于设置权重,第二个则用于设置偏值项;权重和偏置项的初始化参数在`InnerProduct`中进行设置;是否使用偏置项可以使用`bias_term`进行设置。  
PaddlePaddle:权重和偏置项的参数分别使用`param_attr``bias_attr`进行配置,配置参数如下所示,此外将`bias_attr`直接设为`False`表示不使用偏置项。
J
Jason 已提交
53 54 55 56 57 58 59 60 61 62 63
```
paddle.fluid.ParamAttr(
    name=None, 
    initializer=None, 
    learning_rate=1.0, 
    regularizer=None, 
    trainable=True, 
    gradient_clip=None, 
    do_model_average=False
)
```
S
sunyanfang01 已提交
64

J
Jason 已提交
65 66 67
#### 多维输入
Caffe:将输入数据的第一维默认为batch size,其余维度压缩至一维后,得到新的二维输入进行全连接计算;                       
PaddlePaddle:`[0, num_flatten_dims)``[num_flattens_dim, )`维上的数据分别被压缩至一维,得到新的二维输入进行全连接计算。
S
sunyanfang01 已提交
68

J
Jason 已提交
69
#### 其他
S
sunyanfang01 已提交
70 71
Caffe:需要在另一个层中定义激活函数。  
PaddlePaddle:可以通过设置`act`这一参数来确定输出的激活函数。