tf.summary.histogram
Stay organized with collections
Save and categorize content based on your preferences.
Write a histogram summary.
tf.summary.histogram(
name, data, step=None, buckets=None, description=None
)
Used in the notebooks
See also tf.summary.scalar
, tf.summary.SummaryWriter
.
Writes a histogram to the current default summary writer, for later analysis
in TensorBoard's 'Histograms' and 'Distributions' dashboards (data written
using this API will appear in both places). Like tf.summary.scalar
points,
each histogram is associated with a step
and a name
. All the histograms
with the same name
constitute a time series of histograms.
The histogram is calculated over all the elements of the given Tensor
without regard to its shape or rank.
This example writes 2 histograms:
w = tf.summary.create_file_writer('test/logs')
with w.as_default():
tf.summary.histogram("activations", tf.random.uniform([100, 50]), step=0)
tf.summary.histogram("initial_weights", tf.random.normal([1000]), step=0)
A common use case is to examine the changing activation patterns (or lack
thereof) at specific layers in a neural network, over time.
w = tf.summary.create_file_writer('test/logs')
with w.as_default():
for step in range(100):
# Generate fake "activations".
activations = [
tf.random.normal([1000], mean=step, stddev=1),
tf.random.normal([1000], mean=step, stddev=10),
tf.random.normal([1000], mean=step, stddev=100),
]
tf.summary.histogram("layer1/activate", activations[0], step=step)
tf.summary.histogram("layer2/activate", activations[1], step=step)
tf.summary.histogram("layer3/activate", activations[2], step=step)
Arguments |
name
|
A name for this summary. The summary tag used for TensorBoard will be
this name prefixed by any active name scopes.
|
data
|
A Tensor of any shape. The histogram is computed over its elements,
which must be castable to float64 .
|
step
|
Explicit int64 -castable monotonic step value for this summary. If
omitted, this defaults to tf.summary.experimental.get_step() , which must
not be None.
|
buckets
|
Optional positive int . The output will have this many buckets,
except in two edge cases. If there is no data, then there are no buckets.
If there is data but all points have the same value, then all buckets'
left and right endpoints are the same and only the last bucket has nonzero
count. Defaults to 30 if not specified.
|
description
|
Optional long-form description for this summary, as a constant
str . Markdown is supported. Defaults to empty.
|
Returns |
True on success, or false if no summary was emitted because no default
summary writer was available.
|
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. Some content is licensed under the numpy license.
Last updated 2024-04-26 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 2024-04-26 UTC."],[],[],null,["# tf.summary.histogram\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/summary/tb_summary.py#L89-L162) |\n\nWrite a histogram summary. \n\n tf.summary.histogram(\n name, data, step=None, buckets=None, description=None\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|---------------------------------------------------------------------------------|\n| - [Research tools](https://www.tensorflow.org/quantum/tutorials/research_tools) |\n\nSee also [`tf.summary.scalar`](../../tf/summary/scalar), [`tf.summary.SummaryWriter`](../../tf/summary/SummaryWriter).\n\nWrites a histogram to the current default summary writer, for later analysis\nin TensorBoard's 'Histograms' and 'Distributions' dashboards (data written\nusing this API will appear in both places). Like [`tf.summary.scalar`](../../tf/summary/scalar) points,\neach histogram is associated with a `step` and a `name`. All the histograms\nwith the same `name` constitute a time series of histograms.\n\nThe histogram is calculated over all the elements of the given `Tensor`\nwithout regard to its shape or rank.\n\nThis example writes 2 histograms: \n\n w = tf.summary.create_file_writer('test/logs')\n with w.as_default():\n tf.summary.histogram(\"activations\", tf.random.uniform([100, 50]), step=0)\n tf.summary.histogram(\"initial_weights\", tf.random.normal([1000]), step=0)\n\nA common use case is to examine the changing activation patterns (or lack\nthereof) at specific layers in a neural network, over time. \n\n w = tf.summary.create_file_writer('test/logs')\n with w.as_default():\n for step in range(100):\n # Generate fake \"activations\".\n activations = [\n tf.random.normal([1000], mean=step, stddev=1),\n tf.random.normal([1000], mean=step, stddev=10),\n tf.random.normal([1000], mean=step, stddev=100),\n ]\n\n tf.summary.histogram(\"layer1/activate\", activations[0], step=step)\n tf.summary.histogram(\"layer2/activate\", activations[1], step=step)\n tf.summary.histogram(\"layer3/activate\", activations[2], step=step)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `name` | A name for this summary. The summary tag used for TensorBoard will be this name prefixed by any active name scopes. |\n| `data` | A `Tensor` of any shape. The histogram is computed over its elements, which must be castable to `float64`. |\n| `step` | Explicit `int64`-castable monotonic step value for this summary. If omitted, this defaults to [`tf.summary.experimental.get_step()`](../../tf/summary/experimental/get_step), which must not be None. |\n| `buckets` | Optional positive `int`. The output will have this many buckets, except in two edge cases. If there is no data, then there are no buckets. If there is data but all points have the same value, then all buckets' left and right endpoints are the same and only the last bucket has nonzero count. Defaults to 30 if not specified. |\n| `description` | Optional long-form description for this summary, as a constant `str`. Markdown is supported. Defaults to empty. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| True on success, or false if no summary was emitted because no default summary writer was available. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | if a default writer exists, but no step was provided and [`tf.summary.experimental.get_step()`](../../tf/summary/experimental/get_step) is None. |\n\n\u003cbr /\u003e"]]