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)
| 163 | |
| 164 | |
| 165 | def 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 | |
| 191 | def get_checkpoint_path(path): |
no test coverage detected
searching dependent graphs…