Load all variables from a checkpoint to a dict. Args: path(str): path to a checkpoint. Returns: dict: a name:value dict
(path)
| 243 | |
| 244 | |
| 245 | def 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 | |
| 267 | def is_training_name(name): |
nothing calls this directly
no test coverage detected
searching dependent graphs…