1、打印网络信息
import timm import torch from torchsummary import summary model = timm.create_model('regnetx_002', pretrained=False,num_classes=100)##regnety_032 summary(model, ( 3, 1280,960)) timm.list_models('regnet*')
print(model)#打印的是网络每层的信息

?print(summary(model, ( 3, 1280,960)))#打印的是权重信息,参数的权重是按照float32记录的,站4个字节

?
?2、绘制网络结构图
import hiddenlayer as hl
import torch
def save_graph(model, input_size, save_name):
model_graph = hl.build_graph(model, torch.zeros(input_size))
model_graph.theme = hl.graph.THEMES["blue"].copy()
model_graph.save(path="%s_graph.jpg"%save_name, format="jpg")
save_graph(model, (8, 3, 1280,960),"inception_v3")

?3、绘制网络权重
使用的是netron,输入的是pt,网上给出的还会有网络结构但是没实现

?4、利用tensorboard
import torch
import torch.nn as nn
import torch.nn.functional as F
from tensorboardX import SummaryWriter # 用于进行可视化
from torchviz import make_dot
# modelviz = modelViz()
# 创建输入
sampledata = torch.rand(1, 3, 1280,960)
# 看看输出结果对不对
out = model(sampledata)
print(out) # 测试有输出,网络没有问题
# 1. 来用tensorflow进行可视化
with SummaryWriter("./log", comment="sample_model_visualization") as sw:
sw.add_graph(model, sampledata)
# 2. 保存成pt文件后进行可视化
torch.save(model, "./log/regnet.pth")
torch.save(model.state_dict(), "./log/regnet.pt")
# 3. 使用graphviz进行可视化
out = model(sampledata)
g = make_dot(out)
g.render('modelviz', view=False) # 这种方式会生成一个pdf文件
(1)可以利用render生成网络图

?(2)可以利用tensorboard生成网络结构图

?

?
|