使用tensorboardX可視化Pytorch


可視化loss和acc

參考https://www.jianshu.com/p/46eb3004beca

  1. 環境安裝:

    conda activate xxx

    pip install tensorboardX

    pip install tensorflow

  2. 代碼:

    from tensorboardXimport SummaryWriter
    writer = SummaryWriter('runs/001')
    writer.add_scalar('Train/Loss', train_loss / batch_idx, epoch)
    writer.add_scalar('Train/Acc', 100.0 * correct / total, epoch)
    writer.close()
  3. 服務器:

    conda activate xxx

    tensorboard --logdir=runs/001

  4. 本地:

    終端上輸入:ssh -p 22222 -L 6006:localhost:6006 yinwenbin@192.168.2.237

    瀏覽器上輸入:localhost:6006

可視化模型

參考:https://blog.csdn.net/sunqiande88/article/details/80155925?utm_source=copy

import torchvision.models as models
from tensorboardX import SummaryWriter
import torch
model = models.resnet18()
dummy_input = torch.rand(13, 3, 224, 224)
with SummaryWriter(comment='resnet18') as w:
  w.add_graph(model, (dummy_input, ))

conda activate xxx

tensorboard --logdir runs

瀏覽器上輸入:localhost:6006

 

若提示錯誤:'torch._C.Value' object has no attribute 'debugName'

修改tensorboardX 1.9為tensorboardX 1.8

參考:https://blog.csdn.net/East_Plain/article/details/103073311


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM