Exports the model. Args: export_dir_base: A string path to the base export dir. global_step_tensor: An Tensor or tensor name providing the global step counter to append to the export directory path and set in the manifest version. sess: A Session to use to save
(self,
export_dir_base,
global_step_tensor,
sess=None,
exports_to_keep=None)
| 235 | @deprecated("2017-06-30", |
| 236 | "No longer supported. Switch to SavedModel immediately.") |
| 237 | def export(self, |
| 238 | export_dir_base, |
| 239 | global_step_tensor, |
| 240 | sess=None, |
| 241 | exports_to_keep=None): |
| 242 | """Exports the model. |
| 243 | |
| 244 | Args: |
| 245 | export_dir_base: A string path to the base export dir. |
| 246 | global_step_tensor: An Tensor or tensor name providing the |
| 247 | global step counter to append to the export directory path and set |
| 248 | in the manifest version. |
| 249 | sess: A Session to use to save the parameters. |
| 250 | exports_to_keep: a gc.Path filter function used to determine the set of |
| 251 | exports to keep. If set to None, all versions will be kept. |
| 252 | |
| 253 | Returns: |
| 254 | The string path to the exported directory. |
| 255 | |
| 256 | Raises: |
| 257 | RuntimeError: if init is not called. |
| 258 | RuntimeError: if the export would overwrite an existing directory. |
| 259 | """ |
| 260 | if not self._has_init: |
| 261 | raise RuntimeError("init must be called first") |
| 262 | |
| 263 | # Export dir must not end with / or it will break exports to keep. Strip /. |
| 264 | if export_dir_base.endswith("/"): |
| 265 | export_dir_base = export_dir_base[:-1] |
| 266 | |
| 267 | global_step = training_util.global_step(sess, global_step_tensor) |
| 268 | export_dir = os.path.join( |
| 269 | compat.as_bytes(export_dir_base), |
| 270 | compat.as_bytes(constants.VERSION_FORMAT_SPECIFIER % global_step)) |
| 271 | |
| 272 | # Prevent overwriting on existing exports which could lead to bad/corrupt |
| 273 | # storage and loading of models. This is an important check that must be |
| 274 | # done before any output files or directories are created. |
| 275 | if gfile.Exists(export_dir): |
| 276 | raise RuntimeError("Overwriting exports can cause corruption and are " |
| 277 | "not allowed. Duplicate export dir: %s" % export_dir) |
| 278 | |
| 279 | # Output to a temporary directory which is atomically renamed to the final |
| 280 | # directory when complete. |
| 281 | tmp_export_dir = compat.as_text(export_dir) + "-tmp" |
| 282 | gfile.MakeDirs(tmp_export_dir) |
| 283 | |
| 284 | self._saver.save( |
| 285 | sess, |
| 286 | os.path.join( |
| 287 | compat.as_text(tmp_export_dir), |
| 288 | compat.as_text(constants.EXPORT_BASE_NAME)), |
| 289 | meta_graph_suffix=constants.EXPORT_SUFFIX_NAME) |
| 290 | |
| 291 | # Run the asset callback. |
| 292 | if self._assets_callback and self._assets_to_copy: |
| 293 | assets_dir = os.path.join( |
| 294 | compat.as_bytes(tmp_export_dir), |