tensorboard display imcomplete image

enter image description here

why tensorboard display imcomplete image

import torchvision
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
test_data = torchvision.datasets.CIFAR10(root="../torvision/dataset_test", train=False,transform=torchvision.transforms.ToTensor())
test_loader = DataLoader(test_data, batch_size=64, shuffle=False, num_workers=0, drop_last=False)
writer = SummaryWriter("loader_log")
step = 0
for data in test_data:
    img, target = data
    writer.add_image("test_data", img, step)
    step += 1
step_2 = 0
for data_2 in test_loader:
    img_2, target_2 = data_2
    writer.add_images("test_loader", img_2, step_2)
    step_2 += 1
writer.close()

the data_loader should display 64 image

test_data, iterates over the dataset and add each image individually with a unique tag for each image.

test_loader, iterates over the data loader and add entire batches of images as a grid using add_images.

import torchvision
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

test_data = torchvision.datasets.CIFAR10(root="../torvision/dataset_test", train=False, transform=torchvision.transforms.ToTensor())
test_loader = DataLoader(test_data, batch_size=64, shuffle=False, num_workers=0, drop_last=False)
writer = SummaryWriter("loader_log")

# Add images from the test_data one by one
for i, (img, target) in enumerate(test_data):
    writer.add_image(f"test_data/{i}", img, i)

# Add images from the test_loader as batches
for i, (batch_img, batch_target) in enumerate(test_loader):
    writer.add_images("test_loader", batch_img, i)

writer.close()

Leave a Comment