import torch
from torch.utils.tensorboard import SummaryWriter
import matplotlib.pyplot as plt
import numpy as np
def main():
log_path = './log'
logger = SummaryWriter(log_path)
fig, axes = plt.subplots(4, 1, squeeze=False)
for i in range(4):
img = np.arange(10000).reshape((100, 100))
axes[i][0].imshow(img)
audio = torch.randn(10000)
for step in range(1000):
if step % 10 == 0:
logger.add_scalar("Loss/loss1", 2 + step, step)
logger.add_scalar("Loss/loss2", 2 + step, step)
logger.add_figure("fig_tag", fig, step)
logger.add_audio("audio_tag", audio / max(abs(audio)), step, sample_rate=22050)
if __name__ == '__main__':
main()
tensorboard --logdir=log --bind_all
没有bind_all:
TensorBoard 2.5.0 at http://localhost:6006/ (Press CTRL+C to quit)
有bind_all:TensorBoard 2.5.0 at http://N705:6006/ (Press CTRL+C to quit)