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.conv2d
和slim.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配置和上面的是一樣的。