How to display more than 10 images in Tensorboard?

4.3k Views Asked by At

I noticed that it doesn't matter how many image I save to the tensorboard log file, tensorboard will only ever show 10 of them (per tag).

How can we increase the number of images or at least select which ones are displayed?


To reproduce what I mean run following MCVE:

import torch
from torch.utils.tensorboard import SummaryWriter
tb = SummaryWriter(comment="test")

for k in range(100):
    # create an image with some funny pattern
    b = [n for (n, c) in enumerate(bin(k)) if c == '1']
    img = torch.zeros((1,10,10))
    img[0, b, :] = 0.5
    img =img + img.permute([0, 2, 1])

    # add the image to the tensorboard file
    tb.add_image(tag="test", img_tensor=img, global_step=k)

This creates a folder runs in which the data is saved. From the same folder execute tensorboard --logdir runs, open the browser and go to localhost:6006 (or replace 6006 with whatever port tensorboard happens to display after starting it). Then go to the tab called "images" and move the slider above the grayscale image.

In my case it only displayed the images from steps

k = 3, 20, 24, 32, 37, 49, 52, 53, 67, 78

which isn't even an nice even spacing, but looks pretty random. I'd prefer to have

  1. see more than just 10 of the images I saved, and
  2. have a more even spacing of number of steps between each image displayed.

How can I achieve this?

EDIT: I just found the option --samples_per_plugin and tried tensorboard --logdir runs --samples_per_plugin "images=100". This indeed increased the number of images, but it only showed the images from steps k = 0,1,2,3....,78, but none from above 78.

1

There are 1 best solutions below

0
On BEST ANSWER

You probably have to wait a little bit longer to wait for all the data to be loaded, but this is indeed the correct solution, see --help:

--samples_per_plugin: An optional comma separated list of plugin_name=num_samples pairs to explicitly specify how many samples to keep per tag for that plugin. For unspecified plugins, TensorBoard randomly downsamples logged summaries to reasonable values to prevent out-of-memory errors for long running jobs. This flag allows fine control over that downsampling. Note that 0 means keep all samples of that type. For instance, "scalars=500,images=0" keeps 500 scalars and all images. Most users should not need to set this flag. (default: '')

Regarding the random samples: This is also true, there is some sort of randomness to it, from the the FAQ:

Is my data being downsampled? Am I really seeing all the data?

TensorBoard uses reservoir sampling to downsample your data so that it can be loaded into RAM. You can modify the number of elements it will keep per tag in tensorboard/backend/application.py.