Shunya UETA

Software Engineer As Data Scientist

Tensorboard を わずか2行で Jupyter Notebook上で表示

Posted at — Sep 24, 2019

Pytorch 1.2からは公式にTensorboardがサポートされている

Tensorboard とは、学習の状況を可視化できるTensorFlow Family の一種

Jupyte Notebook上で学習状況を確認したい場合に Tensorboardをそのまま表示して確認できれば楽なので、試してみる

sample code:

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 =, batch_size=64, shuffle=True)
model = torchvision.models.resnet50(False)
# 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)



tensorboard in jupyter notebook


comments powered by Disqus