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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM