pytorch中視覺化網路結構方法 1

2021-10-02 00:21:08 字數 1231 閱讀 5936

1.安裝兩個包

pip install tensorboardx

pip install torchsummary

2.例項.

import torch

from torch import nn

from torch.nn import functional as f

from tensorboardx import summarywriter

class mynet(nn.module): # 為了方便自定義的三層網路

def __init__(self):

super(mynet, self).__init__()

self.linear1 = nn.linear(10,16)

self.linear2 = nn.linear(16,10)

self.linear3 = nn.linear(10,5)

def forward(self, x):

x = f.relu(self.linear1(x),inplace=true)

x = f.relu(self.linear2(x),inplace=true)

x = f.relu(self.linear3(x), inplace=true)

return x

x = torch.randn(1,10)

net = mynet()

with summarywriter(comment='mynet') as w:

w.add_graph(net, x)

3.程式執行完成後,會生成乙個run檔案件,找到並開啟該資料夾,在該資料夾中執行

# 注意要與自己的資料夾名字相同

windows在指定資料夾中開啟dos命令視窗的方法:

Pytorch網路結構視覺化

現在用的這個 net load model net,args.trained model,args.cpu for name,param in net.named parameters print param.size name,下面這個報錯 pytorch網路結構視覺化 使用這個 超級強悍 可以通...

Pytorch 網路結構視覺化

conda install graphviz conda install tensorwatch import sys import torch import tensorwatch as tw import torchvision.models alexnet model torchvision....

Caffe 的視覺化 (二)網路結構視覺化

caffe 的視覺化 二 網路結構視覺化 使用caffe裡的工具 draw net.py 該檔案在目錄 caffe root python 裡 usage draw net.py h rankdir rankdir phase phase input net proto file output im...