diff options
Diffstat (limited to 'tensorflow/python/estimator/exporter.py')
-rw-r--r-- | tensorflow/python/estimator/exporter.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/tensorflow/python/estimator/exporter.py b/tensorflow/python/estimator/exporter.py index 62dcbd894b..621dece119 100644 --- a/tensorflow/python/estimator/exporter.py +++ b/tensorflow/python/estimator/exporter.py @@ -35,7 +35,7 @@ class Exporter(object): """Directory name. A directory name under the export base directory where exports of - this type are written. Should not be `None`. + this type are written. Should not be `None` nor empty. """ pass @@ -58,7 +58,7 @@ class Exporter(object): class SavedModelExporter(Exporter): """This class exports the serving graph and checkpoints. - In addition, the class also garbage collects stale exports. + In addition, the class also garbage collects stale exports. """ def __init__(self, @@ -74,23 +74,30 @@ class SavedModelExporter(Exporter): export path. serving_input_fn: a function that takes no arguments and returns an `ServingInputReceiver`. - assets_extra: A dict specifying how to populate the assets.extra directory - within the exported SavedModel. Each key should give the destination - path (including the filename) relative to the assets.extra directory. - The corresponding value gives the full path of the source file to be - copied. For example, the simple case of copying a single file without - renaming it is specified as + assets_extra: An optional dict specifying how to populate the assets.extra + directory within the exported SavedModel. Each key should give the + destination path (including the filename) relative to the assets.extra + directory. The corresponding value gives the full path of the source + file to be copied. For example, the simple case of copying a single + file without renaming it is specified as `{'my_asset_file.txt': '/path/to/my_asset_file.txt'}`. - as_text: whether to write the SavedModel proto in text format. + as_text: whether to write the SavedModel proto in text format. Defaults to + `False`. exports_to_keep: Number of exports to keep. Older exports will be - garbage-collected. Defaults to 5. Set to None to disable garbage + garbage-collected. Defaults to 5. Set to `None` to disable garbage collection. + + Raises: + ValueError: if any arguments is invalid. """ self._name = name self._serving_input_fn = serving_input_fn self._assets_extra = assets_extra self._as_text = as_text self._exports_to_keep = exports_to_keep + if exports_to_keep is not None and exports_to_keep <= 0: + raise ValueError( + '`exports_to_keep`, if provided, must be positive number') @property def name(self): @@ -127,6 +134,7 @@ class SavedModelExporter(Exporter): return None return path._replace(export_version=int(filename)) + # pylint: disable=protected-access keep_filter = gc._largest_export_versions(self._exports_to_keep) delete_filter = gc._negation(keep_filter) for p in delete_filter( @@ -135,3 +143,4 @@ class SavedModelExporter(Exporter): gfile.DeleteRecursively(p.path) except errors_impl.NotFoundError as e: tf_logging.warn('Can not delete %s recursively: %s', p.path, e) + # pylint: enable=protected-access |