MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / load_checkpoint_vars

Function load_checkpoint_vars

tensorpack/tfutils/varmanip.py:245–264  ·  view source on GitHub ↗

Load all variables from a checkpoint to a dict. Args: path(str): path to a checkpoint. Returns: dict: a name:value dict

(path)

Source from the content-addressed store, hash-verified

243
244
245def load_checkpoint_vars(path):
246 """ Load all variables from a checkpoint to a dict.
247
248 Args:
249 path(str): path to a checkpoint.
250
251 Returns:
252 dict: a name:value dict
253 """
254 if path.endswith(".npz"):
255 ret = dict(np.load(path))
256 ret = {get_op_tensor_name(k)[0]: v for k, v in ret.items()}
257 return ret
258 path = get_checkpoint_path(path)
259 reader = tfv1.train.NewCheckpointReader(path)
260 var_names = reader.get_variable_to_shape_map().keys()
261 result = {}
262 for n in var_names:
263 result[n] = reader.get_tensor(n)
264 return result
265
266
267def is_training_name(name):

Callers

nothing calls this directly

Calls 5

get_op_tensor_nameFunction · 0.85
get_checkpoint_pathFunction · 0.85
loadMethod · 0.45
get_tensorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…