MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / save_checkpoint_vars

Function save_checkpoint_vars

tensorpack/tfutils/varmanip.py:165–188  ·  view source on GitHub ↗

Save variables in dic to path. Args: dic: {name: value} path: save as npz if the name ends with '.npz', otherwise save as a checkpoint.

(dic, path)

Source from the content-addressed store, hash-verified

163
164
165def save_checkpoint_vars(dic, path):
166 """
167 Save variables in dic to path.
168
169 Args:
170 dic: {name: value}
171 path: save as npz if the name ends with '.npz', otherwise save as a checkpoint.
172 """
173 logger.info("Variables to save to {}:".format(path))
174 keys = sorted(dic.keys())
175 logger.info(pprint.pformat(keys))
176
177 assert not path.endswith('.npy')
178 if path.endswith('.npz'):
179 np.savez_compressed(path, **dic)
180 else:
181 with tfv1.Graph().as_default(), \
182 tfv1.Session() as sess:
183 for k, v in six.iteritems(dic):
184 k = get_op_tensor_name(k)[0]
185 _ = tfv1.Variable(name=k, initial_value=v) # noqa
186 sess.run(tfv1.global_variables_initializer())
187 saver = tfv1.train.Saver()
188 saver.save(sess, path, write_meta_graph=False)
189
190
191def get_checkpoint_path(path):

Callers 1

dump_session_paramsFunction · 0.85

Calls 4

get_op_tensor_nameFunction · 0.85
formatMethod · 0.80
runMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…