1
Tensorflow中默認的全球variable_scope
是什麼?我如何檢查對象?有沒有人有關於此的想法?Tensorflow中的默認variable_scope是什麼?
Tensorflow中默認的全球variable_scope
是什麼?我如何檢查對象?有沒有人有關於此的想法?Tensorflow中的默認variable_scope是什麼?
從技術上講,對於所有變量沒有全局變量作用域。如果您從腳本的頂層運行
x = tf.Variable(0.0, name='x')
,一個新的變量x
沒有變量範圍將在默認的圖形創建。
不過,這種情況是tf.get_variable()
功能不同的位:
x = tf.get_variable(name='x')
它做的第一件事就是調用tf.get_variable_scope()
函數,它返回當前變量的作用域,進而從查找範圍本地堆棧:
def get_variable_scope():
"""Returns the current variable scope."""
scope = ops.get_collection(_VARSCOPE_KEY)
if scope: # This collection has at most 1 element, the default scope at [0].
return scope[0]
scope = VariableScope(False)
ops.add_to_collection(_VARSCOPE_KEY, scope)
return scope
注意這堆可以是空的,在這種情況下,簡單地創建了一個新的機會和壓入堆棧的頂部。從頂層,或將ops.get_collection(_VARSCOPE_KEY)
直接,如果你是一個範圍內已經
scope = tf.get_variable_scope()
:
如果這是你需要的對象,你可以通過調用訪問它。通過調用tf.get_variable()
函數,這正是新變量的範圍。這是您可以輕鬆檢查的tf.VariableScope
類的普通實例。