tensorflow: arg_scope

arg_scope

tf.contrib.framework.arg_scope(list_ops_or_scope, **kwargs)
#或者 tf.contrib.slim.arg_scope(list_ops_or_scope, **kwargs) # 为给定的 list_ops_or_scope 存储默认的参数

 

示例:

with slim.arg_scope([slim.conv2d, slim.fully_connected], weights_initializer=tf.truncated_normal_initializer(stddev=0.1), weights_regularizer=slim.l2_regularizer(weight_decay), normalizer_fn=slim.batch_norm, normalizer_params=batch_norm_params):

 

就这样给slim.conv2dslim.fully_connected准备了默认参数。

如何给自定义的函数也附上这种功能

from tensorflow.contrib import framework from tensorflow.contrib.framework.python.ops.arg_scope import add_arg_scope @add_arg_scope def haha(name, age): print(name, age) with framework.arg_scope([haha], age = 15): haha("keith") # 输出 # keith 15
with slim.arg_scope(...) as argScope: ... with slim.arg_scope(argScope): ... # argScope 是一个字典。这个字典可以继续使用,下面的arg_scope配置和上面的是一样的。
    原文作者:tensorflow
    原文地址: https://www.cnblogs.com/antflow/p/7268019.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞