8/29 Hourglass网络结构

    with slim.arg_scope(hourglass_arg_scope_tf()):
        # D1
        net2 = slim.conv2d(inputs, 64, (7, 7), 2, scope='conv2-1')
        net2 = bottleneck_module(net2, out_channel=128,
                                res=128, scope='bottleneck2-1')
        
        net2 = slim.max_pool2d(net2, [2, 2], scope='pool2-1')

        # D2
        net2 = slim.stack(net2, bottleneck_module, [
            (128, None), (128, None), (256, 256)], scope='conv2-2')
        
        # hourglasses (D3,D4,D5)
        with tf.variable_scope('hourglass2'):
            net2 = hourglass_module(
                net2, depth=2, deconv=deconv, bottleneck=bottleneck)

       
        # final layers (D6, D7)

        net2 = slim.stack(net2, slim.conv2d, [(512, [1, 1]), (256, [1, 1]),
                                              (48, [1, 1])
                                              ], scope='conv2-3')

        net2 = deconv_layer(net2, 4, 3, method=deconv)  # 反卷积
        
        net2 = slim.conv2d(net3, 3, 1, scope='conv2-last')

    regression2 = slim.conv2d(
        net2, 3, 1, activation_fn=None
    ) if 3 else None
def bottleneck_module(inputs, out_channel=256, res=None, scope=''):
    with tf.variable_scope(scope):
        net = slim.stack(inputs, slim.conv2d, [
            (out_channel // 2, [1, 1]), (out_channel // 2, [3, 3]), (out_channel, [1, 1])], scope='conv')
        if res:
            inputs = slim.conv2d(inputs, res, (1, 1),
                                 scope='bn_res'.format(scope))
        net += inputs

        return net
# recursive hourglass definition
def hourglass_module(inputs, depth=0, deconv='bilinear', bottleneck='bottleneck'):
    bm_fn = globals()['%s_module' % bottleneck]

    with tf.variable_scope('depth_{}'.format(depth)):
        # buttom up layers
        net = slim.max_pool2d(inputs, [2, 2], scope='pool')
        net = slim.stack(net, bm_fn, [
            (256, None), (256, None), (256, None)], scope='buttom_up')

        # connecting layers
        if depth > 0:
            net = hourglass_module(net, depth=depth - 1, deconv=deconv)
        else:
            net = bm_fn(
                net, out_channel=512, res=512, scope='connecting')

        # top down layers
        net = bm_fn(net, out_channel=512,
                    res=512, scope='top_down')
        net = deconv_layer(net, 2, 512, method=deconv)
        # residual layers
        net += slim.stack(inputs, bm_fn,
                          [(256, None), (256, None), (512, 512)], scope='res')

        return net

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值