tf.summary.image
Stay organized with collections
Save and categorize content based on your preferences.
Write an image summary.
tf.summary.image(
name, data, step=None, max_outputs=3, description=None
)
Used in the notebooks
See also tf.summary.scalar
, tf.summary.SummaryWriter
.
Writes a collection of images to the current default summary writer. Data
appears in TensorBoard's 'Images' dashboard. Like tf.summary.scalar
points,
each collection of images is associated with a step
and a name
. All the
image collections with the same name
constitute a time series of image
collections.
This example writes 2 random grayscale images:
w = tf.summary.create_file_writer('test/logs')
with w.as_default():
image1 = tf.random.uniform(shape=[8, 8, 1])
image2 = tf.random.uniform(shape=[8, 8, 1])
tf.summary.image("grayscale_noise", [image1, image2], step=0)
To avoid clipping, data should be converted to one of the following:
- floating point values in the range [0,1], or
- uint8 values in the range [0,255]
# Convert the original dtype=int32 `Tensor` into `dtype=float64`.
rgb_image_float = tf.constant([
[[1000, 0, 0], [0, 500, 1000]],
]) / 1000
tf.summary.image("picture", [rgb_image_float], step=0)
# Convert original dtype=uint8 `Tensor` into proper range.
rgb_image_uint8 = tf.constant([
[[1, 1, 0], [0, 0, 1]],
], dtype=tf.uint8) * 255
tf.summary.image("picture", [rgb_image_uint8], step=1)
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 representing pixel data with shape [k, h, w, c] , where
k is the number of images, h and w are the height and width of the
images, and c is the number of channels, which should be 1, 2, 3, or 4
(grayscale, grayscale with alpha, RGB, RGBA). Any of the dimensions may be
statically unknown (i.e., None ). Floating point data will be clipped to
the range [0,1]. Other data types will be clipped into an allowed range
for safe casting to uint8, using tf.image.convert_image_dtype .
|
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.
|
max_outputs
|
Optional int or rank-0 integer Tensor . At most this many
images will be emitted at each step. When more than max_outputs many
images are provided, the first max_outputs many images will be used and
the rest silently discarded.
|
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.image\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#L165-L244) |\n\nWrite an image summary. \n\n tf.summary.image(\n name, data, step=None, max_outputs=3, description=None\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|--------------------------------------------------------------------------------------------------|\n| - [Displaying image data in TensorBoard](https://www.tensorflow.org/tensorboard/image_summaries) |\n\nSee also [`tf.summary.scalar`](../../tf/summary/scalar), [`tf.summary.SummaryWriter`](../../tf/summary/SummaryWriter).\n\nWrites a collection of images to the current default summary writer. Data\nappears in TensorBoard's 'Images' dashboard. Like [`tf.summary.scalar`](../../tf/summary/scalar) points,\neach collection of images is associated with a `step` and a `name`. All the\nimage collections with the same `name` constitute a time series of image\ncollections.\n\nThis example writes 2 random grayscale images: \n\n w = tf.summary.create_file_writer('test/logs')\n with w.as_default():\n image1 = tf.random.uniform(shape=[8, 8, 1])\n image2 = tf.random.uniform(shape=[8, 8, 1])\n tf.summary.image(\"grayscale_noise\", [image1, image2], step=0)\n\nTo avoid clipping, data should be converted to one of the following:\n\n- floating point values in the range \\[0,1\\], or\n- uint8 values in the range \\[0,255\\]\n\n # Convert the original dtype=int32 `Tensor` into `dtype=float64`.\n rgb_image_float = tf.constant([\n [[1000, 0, 0], [0, 500, 1000]],\n ]) / 1000\n tf.summary.image(\"picture\", [rgb_image_float], step=0)\n\n # Convert original dtype=uint8 `Tensor` into proper range.\n rgb_image_uint8 = tf.constant([\n [[1, 1, 0], [0, 0, 1]],\n ], dtype=tf.uint8) * 255\n tf.summary.image(\"picture\", [rgb_image_uint8], step=1)\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` representing pixel data with shape `[k, h, w, c]`, where `k` is the number of images, `h` and `w` are the height and width of the images, and `c` is the number of channels, which should be 1, 2, 3, or 4 (grayscale, grayscale with alpha, RGB, RGBA). Any of the dimensions may be statically unknown (i.e., `None`). Floating point data will be clipped to the range \\[0,1\\]. Other data types will be clipped into an allowed range for safe casting to uint8, using [`tf.image.convert_image_dtype`](../../tf/image/convert_image_dtype). |\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| `max_outputs` | Optional `int` or rank-0 integer `Tensor`. At most this many images will be emitted at each step. When more than `max_outputs` many images are provided, the first `max_outputs` many images will be used and the rest silently discarded. |\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"]]