Skip to content
Snippets Groups Projects
Commit 5cf18a79 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Exit normally with the earlystop hook

parent 847b6f96
No related branches found
No related tags found
1 merge request!43add logging info to db_to_tfrecords
Pipeline #
include README.rst bootstrap-buildout.py buildout.cfg COPYING version.txt requirements.txt include README.rst buildout.cfg LICENSE version.txt requirements.txt
recursive-include doc *.py *.rst recursive-include doc *.py *.rst
recursive-include bob *.wav *.hdf5 *.pickle *.meta *.ckp *.py *.png recursive-include bob *.wav *.hdf5 *.pickle *.meta *.ckp *.py *.png
...@@ -30,6 +30,11 @@ The configuration files should have the following objects totally: ...@@ -30,6 +30,11 @@ The configuration files should have the following objects totally:
estimator estimator
train_spec train_spec
eval_spec eval_spec
## Optional objects:
exit_ok_exceptions : [Exception]
A list of exceptions to exit properly if they occur. If nothing is
provided, the EarlyStopException is handled by default.
""" """
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import division from __future__ import division
...@@ -40,6 +45,7 @@ import tensorflow as tf ...@@ -40,6 +45,7 @@ import tensorflow as tf
from bob.extension.config import load as read_config_file from bob.extension.config import load as read_config_file
from bob.learn.tensorflow.utils.commandline import \ from bob.learn.tensorflow.utils.commandline import \
get_from_config_or_commandline get_from_config_or_commandline
from bob.learn.tensorflow.utils.hooks import EarlyStopException
from bob.core.log import setup, set_verbosity_level from bob.core.log import setup, set_verbosity_level
logger = setup(__name__) logger = setup(__name__)
...@@ -62,13 +68,21 @@ def main(argv=None): ...@@ -62,13 +68,21 @@ def main(argv=None):
# Sets-up logging # Sets-up logging
set_verbosity_level(logger, verbosity) set_verbosity_level(logger, verbosity)
# required arguments # required objects
estimator = config.estimator estimator = config.estimator
train_spec = config.train_spec train_spec = config.train_spec
eval_spec = config.eval_spec eval_spec = config.eval_spec
# optional objects
exit_ok_exceptions = getattr(config, 'exit_ok_exceptions',
(EarlyStopException,))
# Train and evaluate # Train and evaluate
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec) try:
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
except exit_ok_exceptions as e:
logger.exception(e)
return
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment