Writes a `SavedModel` protocol buffer to disk. The function writes the SavedModel protocol buffer to the export directory in serialized format. Args: as_text: Writes the SavedModel protocol buffer in text format to disk. Protocol buffers in text format are useful for debu
(self, as_text=False)
| 401 | self._has_saved_variables = True |
| 402 | |
| 403 | def save(self, as_text=False): |
| 404 | """Writes a `SavedModel` protocol buffer to disk. |
| 405 | |
| 406 | The function writes the SavedModel protocol buffer to the export directory |
| 407 | in serialized format. |
| 408 | |
| 409 | Args: |
| 410 | as_text: Writes the SavedModel protocol buffer in text format to |
| 411 | disk. Protocol buffers in text format are useful for debugging, but |
| 412 | parsing fails when it encounters an unknown field and so is not forward |
| 413 | compatible. This means changes to TensorFlow may prevent deployment of |
| 414 | new text format SavedModels to existing serving binaries. Do not deploy |
| 415 | `as_text` SavedModels to production. |
| 416 | |
| 417 | Returns: |
| 418 | The path to which the SavedModel protocol buffer was written. |
| 419 | """ |
| 420 | if not file_io.file_exists(self._export_dir): |
| 421 | file_io.recursive_create_dir(self._export_dir) |
| 422 | |
| 423 | if as_text: |
| 424 | path = os.path.join( |
| 425 | compat.as_bytes(self._export_dir), |
| 426 | compat.as_bytes(constants.SAVED_MODEL_FILENAME_PBTXT)) |
| 427 | file_io.write_string_to_file(path, str(self._saved_model)) |
| 428 | else: |
| 429 | path = os.path.join( |
| 430 | compat.as_bytes(self._export_dir), |
| 431 | compat.as_bytes(constants.SAVED_MODEL_FILENAME_PB)) |
| 432 | file_io.write_string_to_file(path, self._saved_model.SerializeToString()) |
| 433 | tf_logging.info("SavedModel written to: %s", compat.as_text(path)) |
| 434 | |
| 435 | return path |
| 436 | |
| 437 | |
| 438 | @tf_export(v1=["saved_model.Builder", "saved_model.builder.SavedModelBuilder"]) # pylint: disable=missing-docstring |