Exemple #1
0
 def compute_gradients(self, loss, var_list=None, **kwargs):
     if var_list is None:
         var_list = variables.trainable_variables() + \
             ops.get_collection(ops.GraphKeys.TRAINABLE_RESOURCE_VARIABLES)
     grads = gradients(loss, var_list)
     grads_and_vars = list(zip(grads, var_list))
     return grads_and_vars
Exemple #2
0
def get_variables(scope=None, suffix=None,
                  collection=ops.GraphKeys.GLOBAL_VARIABLES):
    if isinstance(scope, variable_scope.VariableScope):
        scope = scope.name
    if suffix is not None:
        scope = (scope or '') + '.*' + suffix
    return ops.get_collection(collection, scope)
Exemple #3
0
def get_variables(scope=None, suffix=None,
                  collection=ops.GraphKeys.GLOBAL_VARIABLES):
    if isinstance(scope, variable_scope.VariableScope):
        scope = scope.name
    if suffix is not None:
        scope = (scope or '') + '.*' + suffix
    return ops.get_collection(collection, scope)
Exemple #4
0
def get_variable_scope_store():
    scope_store = ops.get_collection(_GLOBAL_VARIABLE_SCOPE_STORE_KEY)
    if not scope_store:
        scope_store = _VariableScopeStore()
        ops.add_to_collection(_GLOBAL_VARIABLE_SCOPE_STORE_KEY, scope_store)
    else:
        scope_store = scope_store[0]
    return scope_store
Exemple #5
0
    def compute_gradients(self, loss, var_list=None, **kwargs):
        if var_list is None:
            var_list = variables.trainable_variables() + \
                ops.get_collection(ops.GraphKeys.TRAINABLE_RESOURCE_VARIABLES)

        self.loss = loss
        grads = T.grad(loss, var_list)
        grads_and_vars = list(zip(grads, var_list))
        return grads_and_vars
Exemple #6
0
def trainable_variables():
    return ops.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES)
Exemple #7
0
def model_variables():
    return ops.get_collection(ops.GraphKeys.MODEL_VARIABLES)
Exemple #8
0
def local_variables():
    return ops.get_collection(ops.GraphKeys.LOCAL_VARIABLES)
Exemple #9
0
def global_variables():
    return ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)
Exemple #10
0
def trainable_variables():
    return ops.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES)
Exemple #11
0
def model_variables():
    return ops.get_collection(ops.GraphKeys.MODEL_VARIABLES)
Exemple #12
0
def local_variables():
    return ops.get_collection(ops.GraphKeys.LOCAL_VARIABLES)
Exemple #13
0
def global_variables():
    return ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)