• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# TensorFlow Experimental SessionRunHooks
2
3These hooks complement those in tensorflow/python/training. They are instances
4of `SessionRunHook` and are to be used with helpers like `MonitoredSession`
5and `learn.Estimator` that wrap `tensorflow.Session`.
6
7The hooks are called between invocations of `Session.run()` to perform custom
8behavior.
9
10For example the `ProfilerHook` periodically collects `RunMetadata` after
11`Session.run()` and saves profiling information that can be viewed in a
12neat timeline through a Chromium-based web browser (via
13[about:tracing](chrome://tracing)) or the standalone [Catapult](https://github.com/catapult-project/catapult/blob/master/tracing/README.md) tool.
14
15```python
16from tensorflow.contrib.hooks import ProfilerHook
17
18hooks = [ProfilerHook(save_secs=30, output_dir="profiling")]
19with SingularMonitoredSession(hooks=hooks) as sess:
20  while not sess.should_stop():
21    sess.run(some_op)
22```
23
24Or similarly with contrib.learn:
25
26```python
27hooks = [ProfilerHook(save_steps=10, output_dir="profiling")]
28estimator = learn.Estimator(...)
29estimator.fit(input_fn, monitors=hooks)
30```
31