layers_test_config.py 2.3 KB
Newer Older
1
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from paddle.trainer_config_helpers import *

num_classes = 5

x = data_layer(name="input1", size=3)
y = data_layer(name="input2", size=5)

H
Haonan 已提交
22 23
z = out_prod_layer(input1=x, input2=y)

24 25
x1 = fc_layer(input=x, size=5)
y1 = fc_layer(input=y, size=5)
26

Q
qijun 已提交
27 28 29 30 31 32 33 34 35 36 37
z1 = mixed_layer(
    act=LinearActivation(),
    input=[
        conv_operator(
            img=x1,
            filter=y1,
            filter_size=1,
            num_filters=5,
            num_channels=5,
            stride=1)
    ])
38

39 40
assert z1.size > 0

41
y2 = fc_layer(input=y, size=15)
H
Haonan 已提交
42
z2 = rotate_layer(input=y2, height=5, width=3)
43 44 45 46 47 48

cos1 = cos_sim(a=x1, b=y1)
cos3 = cos_sim(a=x1, b=y2, size=3)

linear_comb = linear_comb_layer(weights=x1, vectors=y2, size=3)

Q
qijun 已提交
49
out = fc_layer(
H
Haonan 已提交
50
    input=[cos1, cos3, linear_comb, z, z1, z2],
Q
qijun 已提交
51 52
    size=num_classes,
    act=SoftmaxActivation())
53

54 55
print_layer(input=[out])

56 57
outputs(classification_cost(out, data_layer(name="label", size=num_classes)))

Q
qijun 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71
dotmul = mixed_layer(
    input=[dotmul_operator(
        a=x1, b=x1), dotmul_projection(input=y1)])

proj_with_attr_init = mixed_layer(
    input=full_matrix_projection(
        input=y1,
        param_attr=ParamAttr(
            learning_rate=0, initial_mean=0, initial_std=0)),
    bias_attr=ParamAttr(
        initial_mean=0, initial_std=0, learning_rate=0),
    act=LinearActivation(),
    size=5,
    name='proj_with_attr_init')
72

73
# for ctc
Q
qijun 已提交
74 75 76 77 78
tmp = fc_layer(
    input=[x1, dotmul, proj_with_attr_init],
    size=num_classes + 1,
    act=SoftmaxActivation())
ctc = ctc_layer(input=tmp, label=y, size=num_classes + 1)
E
emailweixu 已提交
79
ctc_eval = ctc_error_evaluator(input=tmp, label=y)
80

81 82 83 84 85
settings(
    batch_size=10,
    learning_rate=2e-3,
    learning_method=AdamOptimizer(),
    regularization=L2Regularization(8e-4),
Q
qijun 已提交
86
    gradient_clipping_threshold=25)