tf.keras.callbacks.TensorBoard
Stay organized with collections
Save and categorize content based on your preferences.
Enable visualizations for TensorBoard.
Inherits From: Callback
tf.keras.callbacks.TensorBoard(
log_dir='logs', histogram_freq=0, write_graph=True, write_images=False,
update_freq='epoch', profile_batch=2, embeddings_freq=0,
embeddings_metadata=None, **kwargs
)
TensorBoard is a visualization tool provided with TensorFlow.
This callback logs events for TensorBoard, including:
- Metrics summary plots
- Training graph visualization
- Activation histograms
- Sampled profiling
If you have installed TensorFlow with pip, you should be able
to launch TensorBoard from the command line:
tensorboard --logdir=path_to_your_logs
You can find more information about TensorBoard
here.
Example (Basic):
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir="./logs")
model.fit(x_train, y_train, epochs=2, callbacks=[tensorboard_callback])
# run the tensorboard command to view the visualizations.
Example (Profile):
# profile a single batch, e.g. the 5th batch.
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir='./logs',
profile_batch=5)
model.fit(x_train, y_train, epochs=2, callbacks=[tensorboard_callback])
# Now run the tensorboard command to view the visualizations (profile plugin).
# profile a range of batches, e.g. from 10 to 20.
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir='./logs',
profile_batch='10,20')
model.fit(x_train, y_train, epochs=2, callbacks=[tensorboard_callback])
# Now run the tensorboard command to view the visualizations (profile plugin).
Arguments |
log_dir
|
the path of the directory where to save the log files to be
parsed by TensorBoard.
|
histogram_freq
|
frequency (in epochs) at which to compute activation and
weight histograms for the layers of the model. If set to 0, histograms
won't be computed. Validation data (or split) must be specified for
histogram visualizations.
|
write_graph
|
whether to visualize the graph in TensorBoard. The log file
can become quite large when write_graph is set to True.
|
write_images
|
whether to write model weights to visualize as image in
TensorBoard.
|
update_freq
|
'batch' or 'epoch' or integer. When using 'batch' ,
writes the losses and metrics to TensorBoard after each batch. The same
applies for 'epoch' . If using an integer, let's say 1000 , the
callback will write the metrics and losses to TensorBoard every 1000
batches. Note that writing too frequently to TensorBoard can slow down
your training.
|
profile_batch
|
Profile the batch(es) to sample compute characteristics.
profile_batch must be a non-negative integer or a tuple of integers.
A pair of positive integers signify a range of batches to profile.
By default, it will profile the second batch. Set profile_batch=0
to disable profiling.
|
embeddings_freq
|
frequency (in epochs) at which embedding layers will be
visualized. If set to 0, embeddings won't be visualized.
|
embeddings_metadata
|
a dictionary which maps layer name to a file name in
which metadata for this embedding layer is saved. See the
details
about metadata files format. In case if the same metadata file is
used for all embedding layers, string can be passed.
|
Raises |
ValueError
|
If histogram_freq is set and no validation data is provided.
|
Methods
set_model
View source
set_model(
model
)
Sets Keras model and writes graph if specified.
set_params
View source
set_params(
params
)
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.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.callbacks.TensorBoard\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/callbacks/TensorBoard) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/python/keras/callbacks.py#L1823-L2266) |\n\nEnable visualizations for TensorBoard.\n\nInherits From: [`Callback`](../../../tf/keras/callbacks/Callback) \n\n tf.keras.callbacks.TensorBoard(\n log_dir='logs', histogram_freq=0, write_graph=True, write_images=False,\n update_freq='epoch', profile_batch=2, embeddings_freq=0,\n embeddings_metadata=None, **kwargs\n )\n\nTensorBoard is a visualization tool provided with TensorFlow.\n\nThis callback logs events for TensorBoard, including:\n\n- Metrics summary plots\n- Training graph visualization\n- Activation histograms\n- Sampled profiling\n\nIf you have installed TensorFlow with pip, you should be able\nto launch TensorBoard from the command line: \n\n tensorboard --logdir=path_to_your_logs\n\nYou can find more information about TensorBoard\n[here](https://www.tensorflow.org/get_started/summaries_and_tensorboard).\n\nExample (Basic): \n\n tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=\"./logs\")\n model.fit(x_train, y_train, epochs=2, callbacks=[tensorboard_callback])\n # run the tensorboard command to view the visualizations.\n\nExample (Profile): \n\n # profile a single batch, e.g. the 5th batch.\n tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir='./logs',\n profile_batch=5)\n model.fit(x_train, y_train, epochs=2, callbacks=[tensorboard_callback])\n # Now run the tensorboard command to view the visualizations (profile plugin).\n\n # profile a range of batches, e.g. from 10 to 20.\n tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir='./logs',\n profile_batch='10,20')\n model.fit(x_train, y_train, epochs=2, callbacks=[tensorboard_callback])\n # Now run the tensorboard command to view the visualizations (profile plugin).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `log_dir` | the path of the directory where to save the log files to be parsed by TensorBoard. |\n| `histogram_freq` | frequency (in epochs) at which to compute activation and weight histograms for the layers of the model. If set to 0, histograms won't be computed. Validation data (or split) must be specified for histogram visualizations. |\n| `write_graph` | whether to visualize the graph in TensorBoard. The log file can become quite large when write_graph is set to True. |\n| `write_images` | whether to write model weights to visualize as image in TensorBoard. |\n| `update_freq` | `'batch'` or `'epoch'` or integer. When using `'batch'`, writes the losses and metrics to TensorBoard after each batch. The same applies for `'epoch'`. If using an integer, let's say `1000`, the callback will write the metrics and losses to TensorBoard every 1000 batches. Note that writing too frequently to TensorBoard can slow down your training. |\n| `profile_batch` | Profile the batch(es) to sample compute characteristics. profile_batch must be a non-negative integer or a tuple of integers. A pair of positive integers signify a range of batches to profile. By default, it will profile the second batch. Set profile_batch=0 to disable profiling. |\n| `embeddings_freq` | frequency (in epochs) at which embedding layers will be visualized. If set to 0, embeddings won't be visualized. |\n| `embeddings_metadata` | a dictionary which maps layer name to a file name in which metadata for this embedding layer is saved. See the [details](https://www.tensorflow.org/how_tos/embedding_viz/#metadata_optional) about metadata files format. In case if the same metadata file is used for all embedding layers, string can be passed. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------------------------|\n| `ValueError` | If histogram_freq is set and no validation data is provided. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `set_model`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/python/keras/callbacks.py#L1966-L1982) \n\n set_model(\n model\n )\n\nSets Keras model and writes graph if specified.\n\n### `set_params`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/python/keras/callbacks.py#L616-L617) \n\n set_params(\n params\n )"]]