pytorch 利用tensorboard显示loss,acc曲线等
运行环境:
python3.6.9 pytorch1.13.1 cuda10.0 cudnn7.5.1
tensorboard显示
运行PointRCNN算法进行training,得出events.out.tfevents.1592297776.hkd-Precision-7920-Tower
打开终端输入:tensorboard --logdir path/to/tensorboard_logs/
会有输出:TensorBoard 1.6.0 at http://iccd:6006 (Press CTRL C to quit)
将上述链接复制到浏览器中打开便可以显示该训练参数(tensorboard)
tensorboard记录
代码语言:javascript复制from tensorboard_logger import Logger
logger = Logger(logdir="./tensorboard_logs", flush_secs=10)
...
def train(net, optimizer):
for epoch in range(epoch_nums):
net.train()
for batch_idx, (inputs, targets) in enumerate(trainloader):
inputs = Variable(inputs, requires_grad=True).cuda()
targets = targets.cuda()
optimizer.zero_grad()
outputs = net(inputs)
loss = criterion(outputs, targets)
loss.backward()
optimizer.step()
train_loss = loss.item()
...
# 记录所需的变量
logger.log_value('avg_loss', train_loss/(batch_idx 1), epoch*len(trainloader) batch_idx)
logger.log_value('loss', loss.item(), epoch*len(trainloader) batch_idx)
logger.log_value('acc', 100. * correct / total, epoch*len(trainloader) batch_idx)
发布者:全栈程序员栈长,转转请注明出处:https://javaforall.cn/2151.html原文链接: