VarScopeObject¶
-
class
tfsnippet.utils.VarScopeObject(name=None, scope=None)¶ Bases:
objectBase class for objects that own a variable scope.
The
VarScopeObjectcan be used along withinstance_reuse(), for example:class YourVarScopeObject(VarScopeObject): @instance_reuse def foo(self): return tf.get_variable('bar', ...) o = YourVarScopeObject('object_name') o.foo() # You should get a variable with name "object_name/foo/bar"
To build variables in the constructor of derived classes, you may use
reopen_variable_scope(self.variable_scope)to open the original variable scope and its name scope, right after the constructor ofVarScopeObjecthas been called, for example:class YourVarScopeObject(VarScopeObject): def __init__(self, name=None, scope=None): super(YourVarScopeObject, self).__init__(name=name, scope=scope) with reopen_variable_scope(self.variable_scope): self.w = tf.get_variable('w', ...)
See also
Attributes Summary
nameGet the name of this object. variable_scopeGet the variable scope of this object. Attributes Documentation
-
name¶ Get the name of this object.
-
variable_scope¶ Get the variable scope of this object.
-