MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / get_variable_by_name

Function get_variable_by_name

tensorflow/python/ops/custom_gradient.py:173–193  ·  view source on GitHub ↗

Given a variable name, retrieves a handle on the tensorflow Variable.

(var_name)

Source from the content-addressed store, hash-verified

171
172
173def get_variable_by_name(var_name):
174 """Given a variable name, retrieves a handle on the tensorflow Variable."""
175
176 candidate_vars = ops.get_collection(
177 ops.GraphKeys.GLOBAL_VARIABLES, scope="{}:0".format(var_name))
178 if len(candidate_vars) >= 1:
179 # Filter out non-trainable variables.
180 candidate_vars = [v for v in candidate_vars if v.trainable]
181 else:
182 raise ValueError("Unsuccessful at finding variable {}.".format(var_name))
183
184 if len(candidate_vars) == 1:
185 return candidate_vars[0]
186 elif len(candidate_vars) > 1:
187 raise ValueError(
188 "Unsuccessful at finding trainable variable {}. "
189 "Number of candidates: {}. "
190 "Candidates: {}".format(var_name, len(candidate_vars), candidate_vars))
191 else:
192 # The variable is not trainable.
193 return None
194
195
196def get_dependent_variables(input_ops, output_ops):

Callers 1

get_dependent_variablesFunction · 0.70

Calls 2

get_collectionMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected