slim.arg_scope的嵌套

在看slim代码中看待这样的结构


with slim.arg_scope([slim.conv2d, slim.fully_connected],
                      activation_fn=tf.nn.relu,
                      biases_initializer=tf.constant_initializer(0.1),
                      weights_regularizer=slim.l2_regularizer(weight_decay)):

  with slim.arg_scope([slim.conv2d], padding='SAME'):

    with slim.arg_scope([slim.max_pool2d], padding='VALID') as arg_sc:

        with slim.arg_scope(arg_sc):

看懵了,改下代码,打印出来。一看,明白了。

with slim.arg_scope([slim.conv2d, slim.fully_connected],
                      activation_fn=tf.nn.relu,
                      biases_initializer=tf.constant_initializer(0.1),
                      weights_regularizer=slim.l2_regularizer(0.005)) as arg_sc0:
    # print(arg_sc0)
    """
    {'<function convolution2d at 0x7f42025f4268>':
        {'activation_fn':
            <function relu at 0x7f4206b3bae8>,
        'biases_initializer':
            <tensorflow.python.ops.init_ops.Constant object at 0x7f4278c62b70>,
        'weights_regularizer':
            <function l2_regularizer.<locals>.l2 at 0x7f425a9dd158>
        },
    '<function fully_connected at 0x7f42025fc1e0>':
        {'activation_fn':
            <function relu at 0x7f4206b3bae8>,
        'biases_initializer':
            <tensorflow.python.ops.init_ops.Constant object at 0x7f4278c62b70>,
        'weights_regularizer':
            <function l2_regularizer.<locals>.l2 at 0x7f425a9dd158>
        }
    }
   """
    with slim.arg_scope([slim.conv2d], padding='SAME') as arg_sc1:
        # print(arg_sc1)
        """
        如果有上面的with
        {'<function convolution2d at 0x7f007d0e7378>':
            {'activation_fn':
                <function relu at 0x7f008161dbf8>,
            'biases_initializer':
                <tensorflow.python.ops.init_ops.Constant object at 0x7f00f3745b70>,
            'weights_regularizer':
                <function l2_regularizer.<locals>.l2 at 0x7f00d54c0158>,
            'padding': 'SAME'
            },
        '<function fully_connected at 0x7f007d0e82f0>':
            {'activation_fn':
                <function relu at 0x7f008161dbf8>,
            'biases_initializer':
                <tensorflow.python.ops.init_ops.Constant object at 0x7f00f3745b70>,
            'weights_regularizer':
                <function l2_regularizer.<locals>.l2 at 0x7f00d54c0158>
            }
        }
        如果没有上面的with
        {'<function convolution2d at 0x7fd4c13bf510>': {'padding': 'SAME'}}
        

        """
        with slim.arg_scope([slim.max_pool2d], padding='VALID') as arg_sc2:
            # print(arg_sc2)
            """
            如果有上面的with
            {'<function convolution2d at 0x7f25c13661e0>':
                {'activation_fn':
                    <function relu at 0x7f25c5873a60>,
                'biases_initializer':
                    <tensorflow.python.ops.init_ops.Constant object at 0x7f26379a0b00>,
                'weights_regularizer':
                    <function l2_regularizer.<locals>.l2 at 0x7f261971b158>,
                'padding':
                    'SAME'},
            '<function fully_connected at 0x7f25c12ed158>':
                {'activation_fn':
                    <function relu at 0x7f25c5873a60>,
                'biases_initializer':
                    <tensorflow.python.ops.init_ops.Constant object at 0x7f26379a0b00>,
                'weights_regularizer':
                    <function l2_regularizer.<locals>.l2 at 0x7f261971b158>},
            '<function max_pool2d at 0x7f25c12b5840>': {
                'padding':
                    'VALID'}}
            如果没有上面的with
            {'<function max_pool2d at 0x7f12d65feb70>': {'padding': 'VALID'}}
            """
            with slim.arg_scope(arg_sc2) as arg_sc:
                print(arg_sc)
                """
                {'<function convolution2d at 0x7f7f5c721488>': 
                    {'activation_fn': 
                        <function relu at 0x7f7f60c58d08>, 
                    'biases_initializer': 
                        <tensorflow.python.ops.init_ops.Constant object at 0x7f7fd2d81ba8>, 
                    'weights_regularizer': 
                        <function l2_regularizer.<locals>.l2 at 0x7f7fb4afc158>, 
                    'padding': 
                        'SAME'}, 
                '<function fully_connected at 0x7f7f5c722400>': 
                    {'activation_fn': 
                        <function relu at 0x7f7f60c58d08>, 
                    'biases_initializer': 
                        <tensorflow.python.ops.init_ops.Constant object at 0x7f7fd2d81ba8>, 
                    'weights_regularizer': 
                        <function l2_regularizer.<locals>.l2 at 0x7f7fb4afc158>
                    }, 
                '<function max_pool2d at 0x7f7f5c6a3ae8>': 
                    {'padding': 
                        'VALID'
                    }
                }
                """

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

颐水风华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值