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)
| 142 | |
| 143 | |
| 144 | def 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 | |
| 165 | def save_checkpoint_vars(dic, path): |
nothing calls this directly
no test coverage detected