tf.estimator.CheckpointSaverListener
bookmark_borderbookmark
Stay organized with collections
Save and categorize content based on your preferences.
Interface for listeners that take action before or after checkpoint save.
View aliases
Compat aliases for migration
See
Migration guide for
more details.
tf.compat.v1.estimator.CheckpointSaverListener
, tf.compat.v1.train.CheckpointSaverListener
CheckpointSaverListener
triggers only in steps when CheckpointSaverHook
is
triggered, and provides callbacks at the following points:
- before using the session
- before each call to
Saver.save()
- after each call to
Saver.save()
- at the end of session
To use a listener, implement a class and pass the listener to a
CheckpointSaverHook
, as in this example:
class ExampleCheckpointSaverListener(CheckpointSaverListener):
def begin(self):
# You can add ops to the graph here.
print('Starting the session.')
self.your_tensor = ...
def before_save(self, session, global_step_value):
print('About to write a checkpoint')
def after_save(self, session, global_step_value):
print('Done writing checkpoint.')
if decided_to_stop_training():
return True
def end(self, session, global_step_value):
print('Done with the session.')
...
listener = ExampleCheckpointSaverListener()
saver_hook = tf.estimator.CheckpointSaverHook(
checkpoint_dir, listeners=[listener])
with
tf.compat.v1.train.MonitoredTrainingSession(chief_only_hooks=[saver_hook]):
...
A CheckpointSaverListener
may simply take some action after every
checkpoint save. It is also possible for the listener to use its own schedule
to act less frequently, e.g. based on global_step_value. In this case,
implementors should implement the end()
method to handle actions related to
the last checkpoint save. But the listener should not act twice if
after_save()
already handled this last checkpoint save.
A CheckpointSaverListener
can request training to be stopped, by returning
True in after_save
. Please note that, in replicated distributed training
setting, only chief
should use this behavior. Otherwise each worker will do
their own evaluation, which may be wasteful of resources.
Methods
after_save
View source
after_save(
session, global_step_value
)
before_save
View source
before_save(
session, global_step_value
)
begin
View source
begin()
end
View source
end(
session, global_step_value
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[],null,["# tf.estimator.CheckpointSaverListener\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/training/basic_session_run_hooks.py#L446-L509) |\n\nInterface for listeners that take action before or after checkpoint save.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.estimator.CheckpointSaverListener`](/api_docs/python/tf/estimator/CheckpointSaverListener), [`tf.compat.v1.train.CheckpointSaverListener`](/api_docs/python/tf/estimator/CheckpointSaverListener)\n\n\u003cbr /\u003e\n\n`CheckpointSaverListener` triggers only in steps when `CheckpointSaverHook` is\ntriggered, and provides callbacks at the following points:\n\n- before using the session\n- before each call to `Saver.save()`\n- after each call to `Saver.save()`\n- at the end of session\n\nTo use a listener, implement a class and pass the listener to a\n`CheckpointSaverHook`, as in this example: \n\n class ExampleCheckpointSaverListener(CheckpointSaverListener):\n def begin(self):\n # You can add ops to the graph here.\n print('Starting the session.')\n self.your_tensor = ...\n\n def before_save(self, session, global_step_value):\n print('About to write a checkpoint')\n\n def after_save(self, session, global_step_value):\n print('Done writing checkpoint.')\n if decided_to_stop_training():\n return True\n\n def end(self, session, global_step_value):\n print('Done with the session.')\n\n ...\n listener = ExampleCheckpointSaverListener()\n saver_hook = tf.estimator.CheckpointSaverHook(\n checkpoint_dir, listeners=[listener])\n with\n tf.compat.v1.train.MonitoredTrainingSession(chief_only_hooks=[saver_hook]):\n ...\n\nA `CheckpointSaverListener` may simply take some action after every\ncheckpoint save. It is also possible for the listener to use its own schedule\nto act less frequently, e.g. based on global_step_value. In this case,\nimplementors should implement the `end()` method to handle actions related to\nthe last checkpoint save. But the listener should not act twice if\n`after_save()` already handled this last checkpoint save.\n\nA `CheckpointSaverListener` can request training to be stopped, by returning\nTrue in `after_save`. Please note that, in replicated distributed training\nsetting, only `chief` should use this behavior. Otherwise each worker will do\ntheir own evaluation, which may be wasteful of resources.\n\nMethods\n-------\n\n### `after_save`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/training/basic_session_run_hooks.py#L505-L506) \n\n after_save(\n session, global_step_value\n )\n\n### `before_save`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/training/basic_session_run_hooks.py#L502-L503) \n\n before_save(\n session, global_step_value\n )\n\n### `begin`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/training/basic_session_run_hooks.py#L499-L500) \n\n begin()\n\n### `end`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/training/basic_session_run_hooks.py#L508-L509) \n\n end(\n session, global_step_value\n )"]]