pytorch - Some steps are missing when adding multiple images under the same tag in TensorBoard - Stack Overflow

I’m adding multiple images in a loop under the same tag using writer.add_image(). However, in TensorBoa

I’m adding multiple images in a loop under the same tag using writer.add_image(). However, in TensorBoard, some steps are missing or not displayed.

Code That Causes the Issue:

from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms # 工具箱
import cv2
from PIL import Image

writer = SummaryWriter("runs/ts_logs")

# totensor 转化为 tensor 数据类型
img_path = "/Users/zhouzihao/development/ML/pytorchLearn/hymenoptera_data/train/ants/6240338_93729615ec.jpg"
img = Image.open(img_path)

trans_totensor = transforms.ToTensor() # 实例化,创建具体的工具
img_tensor = trans_totensor(img) # 使用工具

print(img_tensor)

writer.add_image("tensor_img", img_tensor)

# normalize 归一化
trans_norm = transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
img_norm = trans_norm(img_tensor)
writer.add_image("norm_img", img_norm)

# resize 缩放
trans_resize = transforms.Resize((512, 512))
img_resize = trans_resize(img_tensor)
writer.add_image("resize_img", img_resize, 0)

# compose 串处理
trans_resize_2 = transforms.Resize(1024)
trans_compose = transforms.Compose([trans_resize_2, trans_totensor])
img_compose = trans_compose(img)
writer.add_image("resize_img", img_compose, 1)

# randomcrop 随机裁剪
trans_random = transforms.RandomCrop(512)
for i in range(10):
    img_crop = trans_random(img_compose)
    writer.add_image("random_crop", img_crop, i)

writer.close()


  • Expected Result:

All 10 cropped images should be visible under the same tag random_crop in TensorBoard, with each one corresponding to its own step (0–9), accessible via the step slider.

  • Actual Result:

Only some steps are displayed. Others are missing or not rendered, even though no errors are raised during logging.

  • Environment:

TensorBoard: 2.14.0

PyTorch: 2.4.1

Browser: Chrome

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744260965a4565631.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信