MCPcopy Index your code
hub / github.com/tensorlayer/TensorLayer / ckpt_to_npz_dict

Function ckpt_to_npz_dict

tensorlayer/files/utils.py:2862–2896  ·  view source on GitHub ↗

Save ckpt weights to npz file Parameters ---------- model_dir : str Filename to which the weights will be loaded, should be of ckpt format. Examples: model_dir = /root/cnn_model/ save_name : str The save_name of the `.npz` file. rename_key : bool

(model_dir, save_name='model.npz', rename_key=False)

Source from the content-addressed store, hash-verified

2860
2861
2862def ckpt_to_npz_dict(model_dir, save_name='model.npz', rename_key=False):
2863 """ Save ckpt weights to npz file
2864
2865 Parameters
2866 ----------
2867 model_dir : str
2868 Filename to which the weights will be loaded, should be of ckpt format.
2869 Examples: model_dir = /root/cnn_model/
2870 save_name : str
2871 The save_name of the `.npz` file.
2872 rename_key : bool
2873 Modify parameter naming, used to match TL naming rule.
2874 Examples: conv1_1/b_b --> conv1_1/biases:0 ; conv1_1/w_w --> conv1_1/filters:0
2875
2876 Returns
2877 -------
2878
2879 """
2880 model_path, _ = check_ckpt_file(model_dir)
2881
2882 reader = pywrap_tensorflow.NewCheckpointReader(model_path)
2883 var_to_shape_map = reader.get_variable_to_shape_map()
2884
2885 parameters_dict = {}
2886 if rename_key is False:
2887 for key in sorted(var_to_shape_map):
2888 parameters_dict[key] = reader.get_tensor(key)
2889 elif rename_key is True:
2890 for key in sorted(var_to_shape_map):
2891 parameters_dict[rename_weight_or_biases(key)] = reader.get_tensor(key)
2892
2893 np.savez(save_name, **parameters_dict)
2894 parameters_dict = None
2895 del parameters_dict
2896 logging.info("[*] Ckpt weights saved in npz_dict %s" % save_name)

Callers

nothing calls this directly

Calls 2

check_ckpt_fileFunction · 0.85
rename_weight_or_biasesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…