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

Function dump_session_params

tensorpack/tfutils/varmanip.py:144–162  ·  view source on GitHub ↗

Dump value of all TRAINABLE + MODEL variables to a dict, and save as npz format (loadable by :func:`sessinit.SmartInit`). Args: path(str): the file name to save the parameters. Must ends with npz.

(path)

Source from the content-addressed store, hash-verified

142
143
144def dump_session_params(path):
145 """
146 Dump value of all TRAINABLE + MODEL variables to a dict, and save as
147 npz format (loadable by :func:`sessinit.SmartInit`).
148
149 Args:
150 path(str): the file name to save the parameters. Must ends with npz.
151 """
152 # save variables that are GLOBAL, and either TRAINABLE or MODEL
153 var = tfv1.get_collection(tfv1.GraphKeys.TRAINABLE_VARIABLES)
154 var.extend(tfv1.get_collection(tfv1.GraphKeys.MODEL_VARIABLES))
155 # TODO dedup
156 assert len(set(var)) == len(var), "TRAINABLE and MODEL variables have duplication!"
157 gvars = {k.name for k in tfv1.global_variables()}
158 var = [v for v in var if v.name in gvars]
159 result = {}
160 for v in var:
161 result[v.name] = v.eval()
162 save_checkpoint_vars(result, path)
163
164
165def save_checkpoint_vars(dic, path):

Callers

nothing calls this directly

Calls 3

save_checkpoint_varsFunction · 0.85
get_collectionMethod · 0.80
evalMethod · 0.80

Tested by

no test coverage detected