gpt4 book ai didi

tensorflow - 为什么 TensorBoard 摘要没有更新?

转载 作者:行者123 更新时间:2023-12-04 00:51:38 53 4
gpt4 key购买 nike

我使用带有 pytorch1.1 的 tensorboard 来记录损失值。

我用 writer.add_scalar("loss", loss.item(), global_step)在每个for循环体中。

但是,在训练过程中绘图图不会更新。

每次想看到最新的损失,都得重启tensorboard服务器。

代码在这里

import torch
import torch.nn as nn
import torch.nn.functional as F
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)
# Have ResNet model take in grayscale rather than RGB
model.conv1 = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3, bias=False)
model.fc = nn.Linear(2048, 10, True)

criterion = nn.CrossEntropyLoss()

epochs = 100

opt = torch.optim.Adam(model.parameters())

niter = 0

for epoch in range(epochs):
for step, (x, y) in enumerate(trainloader):
yp = model(x)
loss = criterion(yp, y)
opt.zero_grad()
loss.backward()
opt.step()
writer.add_scalar("loss", loss.item(), niter)
niter += 1
print(loss.item())

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

训练还在继续,全局步数已经是3594了,但是tensorboard还是显示在1900左右。

enter image description here

最佳答案

同样对于单次运行有多个事件日志文件的人,您需要使用 --reload_multifile True 启动张量板。

关于tensorflow - 为什么 TensorBoard 摘要没有更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55980785/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com