无法使用torch.utils.tensorboard.SummaryWriter.add_graph方法加载保存的图形

时间:2019-08-29 08:36:50

标签: python pytorch tensorboard

我正在使用add_scalar中的add_graphtorch.utils.tensorboard.SummaryWriter方法保存标量摘要以及模型图。

在摘要文件上运行tensorboard时,它不显示模型图。右下角只有2个小矩形,但是,它可以显示标量变量和图像。

随附的pytorch文档中的示例代码

import torch
import torchvision
from torch.utils.tensorboard import SummaryWriter
from torchvision import datasets, transforms

# Writer will output to ./runs/ directory by default
writer = SummaryWriter()

transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))])
trainset = datasets.MNIST('mnist_train', train=True, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)
model = torchvision.models.resnet50(False)

print(model)

# Have ResNet model take in grayscale rather than RGB
model.conv1 = torch.nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3, bias=False)
images, labels = next(iter(trainloader))

grid = torchvision.utils.make_grid(images)
writer.add_image('images', grid, 0)
writer.add_graph(model, images)
writer.close()

任何指向该解决方案的指针将不胜感激

  

PyTorch版本-1.2.0 Tensorboard版本-1.15.0a20190828

Attaching the bottom right crop of the tensorboard

1 个答案:

答案 0 :(得分:1)

我有同样的问题。 看看这个线程: https://github.com/pytorch/pytorch/issues/24157

TLDR:每晚将PyTorch更新为PyTorch,此问题应得到解决。 https://pytorch.org/get-started/locally/