tf.summary.scalar
Stay organized with collections
Save and categorize content based on your preferences.
Write a scalar summary.
tf.summary.scalar(
name, data, step=None, description=None
)
Used in the notebooks
See also tf.summary.image
, tf.summary.histogram
,
tf.summary.SummaryWriter
.
Writes simple numeric values for later analysis in TensorBoard. Writes go to
the current default summary writer. Each summary point is associated with an
integral step
value. This enables the incremental logging of time series
data. A common usage of this API is to log loss during training to produce
a loss curve.
For example:
test_summary_writer = tf.summary.create_file_writer('test/logdir')
with test_summary_writer.as_default():
tf.summary.scalar('loss', 0.345, step=1)
tf.summary.scalar('loss', 0.234, step=2)
tf.summary.scalar('loss', 0.123, step=3)
Multiple independent time series may be logged by giving each series a unique
name
value.
See Get started with
TensorBoard
for more examples of effective usage of tf.summary.scalar
.
In general, this API expects that data points are logged with a monotonically
increasing step value. Duplicate points for a single step or points logged out
of order by step are not guaranteed to display as desired in TensorBoard.
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 real numeric scalar value, convertible to a float32 Tensor.
|
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.
|
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 written 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.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.summary.scalar\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#L247-L303) |\n\nWrite a scalar summary. \n\n tf.summary.scalar(\n name, data, step=None, description=None\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [pix2pix: Image-to-image translation with a conditional GAN](https://www.tensorflow.org/tutorials/generative/pix2pix) - [TensorBoard Scalars: Logging training metrics in Keras](https://www.tensorflow.org/tensorboard/scalars_and_keras) - [Get started with TensorBoard](https://www.tensorflow.org/tensorboard/get_started) - [Research tools](https://www.tensorflow.org/quantum/tutorials/research_tools) - [Migrating tf.summary usage to TF 2.x](https://www.tensorflow.org/tensorboard/migrate) |\n\nSee also [`tf.summary.image`](../../tf/summary/image), [`tf.summary.histogram`](../../tf/summary/histogram),\n[`tf.summary.SummaryWriter`](../../tf/summary/SummaryWriter).\n\nWrites simple numeric values for later analysis in TensorBoard. Writes go to\nthe current default summary writer. Each summary point is associated with an\nintegral `step` value. This enables the incremental logging of time series\ndata. A common usage of this API is to log loss during training to produce\na loss curve.\n\n#### For example:\n\n test_summary_writer = tf.summary.create_file_writer('test/logdir')\n with test_summary_writer.as_default():\n tf.summary.scalar('loss', 0.345, step=1)\n tf.summary.scalar('loss', 0.234, step=2)\n tf.summary.scalar('loss', 0.123, step=3)\n\nMultiple independent time series may be logged by giving each series a unique\n`name` value.\n\nSee [Get started with\nTensorBoard](https://www.tensorflow.org/tensorboard/get_started)\nfor more examples of effective usage of [`tf.summary.scalar`](../../tf/summary/scalar).\n\nIn general, this API expects that data points are logged with a monotonically\nincreasing step value. Duplicate points for a single step or points logged out\nof order by step are not guaranteed to display as desired in TensorBoard.\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 real numeric scalar value, convertible to a `float32` Tensor. |\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| `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 written 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"]]