避免自己采坑...(以下是本人安装版本)
1.安装python3.6+pytorch1.0.0
2.安装 torchvision 0.2
pip install torchvision
3.安装Tensorflow和Tensorboard :清华镜像网站下载
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow
pip install tensorboard==1.7.0
4.安装TensorboardX
pip install tensorboardX==1.8
5.运行demo.py 编码方式UTF-8
# _*_ coding: utf-8 _*_
import torch
import torch.nn as nn
from tensorboardX import SummaryWriter
class LeNet(nn.Module):
def __init__(self):
super(LeNet, self).__init__()
self.conv1 = nn.Sequential( #input_size=(1*28*28)
nn.Conv2d(1, 6, 5, 1, 2),
nn.ReLU(), #(6*28*28)
nn.MaxPool2d(kernel_size=2, stride=2), #output_size=(6*14*14)
)
self.conv2 = nn.Sequential(
nn.Conv2d(6, 16, 5),
nn.ReLU(), #(16*10*10)
nn.MaxPool2d(2, 2) #output_size=(16*5*5)
)
self.fc1 = nn.Sequential(
nn.Linear(16 * 5 * 5, 120),
nn.ReLU()
)
self.fc2 = nn.Sequential(
nn.Linear(120, 84),
nn.ReLU()
)
self.fc3 = nn.Linear(84, 10)
# 定义前向传播过程,输入为x
def forward(self, x):
x = self.conv1(x)
x = self.conv2(x)
# nn.Linear()的输入输出都是维度为一的值,所以要把多维度的tensor展平成一维
x = x.view(x.size()[0], -1)
x = self.fc1(x)
x = self.fc2(x)
x = self.fc3(x)
return x
dummy_input = torch.rand(13, 1, 28, 28) #假设输入13张1*28*28的图片
model = LeNet()
with SummaryWriter(comment='LeNet') as w:
w.add_graph(model, (dummy_input, ))
6. 运行demo.py,会生成runs文件夹,输入:
tensorboard --logdir runs
会生成一个网址,复制网址,在谷歌浏览器中打开。
7.可视化的界面
踩雷解决
1. AttributeError: 'torch._C.Value' object has no attribute 'debugName'
TensorboardX版本太高,卸载后安装低版本TensorboardX。