|View source on GitHub|
Given an arbitrary function, wrap it so that it does variable sharing.
tf.compat.v1.make_template( name_, func_, create_scope_now_=False, unique_name_=None, custom_getter_=None, **kwargs )
func_ in a Template and partially evaluates it. Templates are
functions that create variables the first time they are called and reuse them
thereafter. In order for
func_ to be compatible with a
Template it must
have the following properties:
- The function should create all trainable variables and any variables that
should be reused by calling
tf.compat.v1.get_variable. If a trainable variable is created using
tf.Variable, then a ValueError will be thrown. Variables that are intended to be locals can be created by specifying
- The function may use variable scopes and other templates internally to
create and reuse variables, but it shouldn't use
tf.compat.v1.global_variablesto capture variables that are defined outside of the scope of the function.
- Internal scopes and variable names should not depend on any arguments that
are not supplied to
make_template. In general you will get a ValueError telling you that you are trying to reuse a variable that doesn't exist if you make a mistake.
In the following example, both