face_landmark.py 3.2 KB
Newer Older
W
wuzewu 已提交
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
# coding=utf-8
from __future__ import absolute_import

import paddle.fluid as fluid

__all__ = ["face_landmark_localization"]


def face_landmark_localization(image):
    # image = fluid.layers.data(shape=[1, 60, 60], name='data', dtype='float32')
    Conv1 = fluid.layers.conv2d(
        image,
        param_attr='Conv1_weights',
        name='Conv1',
        dilation=[1, 1],
        filter_size=[5, 5],
        stride=[1, 1],
        groups=1,
        bias_attr='Conv1_bias',
        padding=[2, 2],
        num_filters=20)
    ActivationTangH1 = fluid.layers.tanh(Conv1, name='ActivationTangH1')
    ActivationAbs1 = fluid.layers.abs(ActivationTangH1, name='ActivationAbs1')
    Pool1 = fluid.layers.pool2d(
        ActivationAbs1,
        exclusive=False,
        pool_type='max',
        pool_padding=[0, 0],
        name='Pool1',
        global_pooling=False,
        pool_stride=[2, 2],
        ceil_mode=True,
        pool_size=[2, 2])
    Conv2 = fluid.layers.conv2d(
        Pool1,
        param_attr='Conv2_weights',
        name='Conv2',
        dilation=[1, 1],
        filter_size=[5, 5],
        stride=[1, 1],
        groups=1,
        bias_attr='Conv2_bias',
        padding=[2, 2],
        num_filters=48)
    ActivationTangH2 = fluid.layers.tanh(Conv2, name='ActivationTangH2')
    ActivationAbs2 = fluid.layers.abs(ActivationTangH2, name='ActivationAbs2')
    Pool2 = fluid.layers.pool2d(
        ActivationAbs2,
        exclusive=False,
        pool_type='max',
        pool_padding=[0, 0],
        name='Pool2',
        global_pooling=False,
        pool_stride=[2, 2],
        ceil_mode=True,
        pool_size=[2, 2])
    Conv3 = fluid.layers.conv2d(
        Pool2,
        param_attr='Conv3_weights',
        name='Conv3',
        dilation=[1, 1],
        filter_size=[3, 3],
        stride=[1, 1],
        groups=1,
        bias_attr='Conv3_bias',
        padding=[0, 0],
        num_filters=64)
    ActivationTangH3 = fluid.layers.tanh(Conv3, name='ActivationTangH3')
    ActivationAbs3 = fluid.layers.abs(ActivationTangH3, name='ActivationAbs3')
    Pool3 = fluid.layers.pool2d(
        ActivationAbs3,
        exclusive=False,
        pool_type='max',
        pool_padding=[0, 0],
        name='Pool3',
        global_pooling=False,
        pool_stride=[2, 2],
        ceil_mode=True,
        pool_size=[3, 3])
    Conv4 = fluid.layers.conv2d(
        Pool3,
        param_attr='Conv4_weights',
        name='Conv4',
        dilation=[1, 1],
        filter_size=[3, 3],
        stride=[1, 1],
        groups=1,
        bias_attr='Conv4_bias',
        padding=[0, 0],
        num_filters=80)
    ActivationTangH4 = fluid.layers.tanh(Conv4, name='ActivationTangH4')
    ActivationAbs4 = fluid.layers.abs(ActivationTangH4, name='ActivationAbs4')
    Dense1 = fluid.layers.fc(
W
wuzewu 已提交
94
        ActivationAbs4, param_attr='Dense1_weights', act=None, name='Dense1', size=512, bias_attr='Dense1_bias')
W
wuzewu 已提交
95 96 97
    ActivationTangH5 = fluid.layers.tanh(Dense1, name='ActivationTangH5')
    ActivationAbs5 = fluid.layers.abs(ActivationTangH5, name='ActivationAbs5')
    Dense3 = fluid.layers.fc(
W
wuzewu 已提交
98
        ActivationAbs5, param_attr='Dense3_weights', act=None, name='Dense3', size=136, bias_attr='Dense3_bias')
W
wuzewu 已提交
99
    return Dense3