Pytorch 网络结构可视化

pytorch网络结构可视化 torchviz.py文件 import torch from torch.autograd import Variable from graphviz import Digraph def make_dot(var, params=None): """ 画出 PyTorch 自动梯度图 autograd graph 的 Graphviz 表示. 蓝色节点表示有梯度计... 阅读详情
文自:深度学习这件小事

安装

可以通过以下的命令进行安装

conda install pytorch-nightly -c pytorch
conda install graphviz
conda install torchvision
conda install tensorwatch

本教程基于以下的版本:

torchvision.__version__   '0.2.1'
torch.__version__         '1.2.0.dev20190610'
sys.version               '3.6.8 |Anaconda custom (64-bit)| (default, Dec 30 2018, 01:22:34)
[GCC 7.3.0]'

载入库

import sys
import torch
import tensorwatch as tw
import torchvision.models

网络结构可视化

alexnet_model = torchvision.models.alexnet()
tw.draw_model(alexnet_model, [1, 3, 224, 224])

载入alexnet,draw_model函数需要传入三个参数,第一个为model,第二个参数为input_shape,第三个参数为orientation,可以选择'LR'或者'TB',分别代表左右布局与上下布局。

在notebook中,执行完上面的代码会显示如下的图,将网络的结构及各个层的name和shape进行了可视化。

统计网络参数

可以通过model_stats方法统计各层的参数情况。

tw.model_stats(alexnet_model, [1, 3, 224, 224])

[MAdd]: Dropout is not supported!
[Flops]: Dropout is not supported!
[Memory]: Dropout is not supported!
[MAdd]: Dropout is not supported!
[Flops]: Dropout is not supported!
[Memory]: Dropout is not supported!
[MAdd]: Dropout is not supported!
[Flops]: Dropout is not supported!
[Memory]: Dropout is not supported!
[MAdd]: Dropout is not supported!
[Flops]: Dropout is not supported!
[Memory]: Dropout is not supported!
[MAdd]: Dropout is not supported!
[Flops]: Dropout is not supported!
[Memory]: Dropout is not supported!
[MAdd]: Dropout is not supported!
[Flops]: Dropout is not supported!
[Memory]: Dropout is not supported!
alexnet_model.features

Sequential(
  (0): Conv2d(3, 64, kernel_size=(11, 11), stride=(4, 4), padding=(2, 2))
  (1): ReLU(inplace=True)
  (2): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)
  (3): Conv2d(64, 192, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
  (4): ReLU(inplace=True)
  (5): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)
  (6): Conv2d(192, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
  (7): ReLU(inplace=True)
  (8): Conv2d(384, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
  (9): ReLU(inplace=True)
  (10): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
  (11): ReLU(inplace=True)
  (12): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)
)

alexnet_model.classifier

Sequential(
  (0): Dropout(p=0.5)
  (1): Linear(in_features=9216, out_features=4096, bias=True)
  (2): ReLU(inplace=True)
  (3): Dropout(p=0.5)
  (4): Linear(in_features=4096, out_features=4096, bias=True)
  (5): ReLU(inplace=True)
  (6): Linear(in_features=4096, out_features=1000, bias=True)
)

参考:

https://github.com/microsoft/tensorwatch



【DL】PyTorch 网络结构可视化graphviz + torchviz viz 阅读详情

相关推荐

Pytorch网络结构可视化

现在用的这个: net = load_model(net, args.trained_model, args.cpu) for name, param in net.named_parameters(): print(param.size(),name, ) 下面这个报错: Pytorch网络结构可视化 使用这个网址,超级强悍 https://lut...

jacke121的专栏 2604

PyTorch实现的VGGNet

PyTorch实现的VGGNet PyTorch: https://github.com/shanglianlm0525/ClassicNetwork PyTorch代码

mingo_敏 4941

Pytorch Note57 Pytorch可视化网络结构

Pytorch Note57 Pytorch可视化网络结构 文章目录Pytorch Note57 Pytorch可视化网络结构使用print打印torchinfo可视化安装torchinfo或者torchsummary使用torchinfo 全部笔记的汇总贴:Pytorch Note 快乐星球 随着深度神经网络做的的发展,网络的结构越来越复杂,我们也很难确定每一层的输入结构,输出结构以及参数等信息,这样导致我们很难在短时间内完成debug。因此掌握一个可以用来可视化网络结构的工具是十分有必要的。类似的功能

风信子的猫Redamancy的快乐星球 2694

PyTorch下的可视化工具(网络结构/训练过程可视化)

点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达作者 | 锦恢@知乎来源 | https://zhuanlan.zhihu.com/p/220403674编辑 | 极市平台本文仅作学术分享,如有侵权请联系删除。导读本文大致想说一下pytorch下的网络结构可视化和训练过程可视化。一、网络结构的可视化我们训练神经网络时,除了随着step或者epoch观察损失函数的走势,...

小白学视觉 6021

Pytorch tensorboardX 网络结构可视化报错

1,设置使用CPU、GPU # 使用 CPU import os os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # 使用 GPU from utee import misc args.gpu = misc.auto_select_gpu(utility_bound=0, num_gpu=args.ngpu, selected_gpus=args.gpu)...

Hello Word! 3527

Pytorch 模型的网络结构可视化 pytorchviz

一、安装命令: sudo pip install graphviz # 或 sudo pip install git+https://github.com/szagoruyko/pytorchviz 二、报错问题 使用graphviz 生成树报错(graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'Digraph.gv']) 解决方法: 首先,在官网上下载软件,安装完成后,手动配置环境变量或

星月夜话 1660

win11系统下Anaconda,PyTorch,cuda 最新安装教程(2022-10-26)

Pytorch 、Anaconda和Cuda的安装

生息万物的博客 7127

雪亮工程视频联网技术详解:视综平台主流接入方式与协议分析

随着雪亮工程建设的深入,视频资源的汇聚与共享成为核心需求。本文简要剖析了雪亮视综平台下的视频联网接入技术,重点讲解了主流接入方式的区别与选型,并深入探讨了平台内部及跨平台的视频资源共享机制(含级联与推送模式),旨在为安防开发人员和系统集成商提供清晰的架构思路与技术参考。

lsz152590的博客 723

pytorch打印网络结构_PyTorch下的可视化工具

toc无效QAQ,反正大致想说一下pytorch下的网络结构可视化和训练过程可视化。一、网络结构的可视化我们训练神经网络时,除了随着step或者epoch观察损失函数的走势,从而建立对目前网络优化的基本认知外,也可以通过一些额外的可视化库来可视化我们的神经网络结构图。这将更加地高效地向读者展现目前的网络结构。为了可视化神经网络,我们先建立一个简单的卷积层神经网络: import torch im...

weixin_39671631的博客 4775

无感健康监测的未来:毫米波雷达如何重新定义睡眠科技与居家养老

毫米波雷达技术正重新定义无感健康监测,特别是在睡眠科技与居家养老领域。通过精准监测呼吸、心率和体动,无需穿戴设备即可实现临床级精度。结合合宙Air700E开发板,构建了完整的远程看护解决方案,为老年人提供跌倒检测、异常报警等安全保障,同时保护用户隐私。

cake8的博客 570

碳化硅外延层厚度测量:红外干涉光谱与FFT技术详解

薄膜厚度测量是半导体制造中的关键工艺控制环节,其核心原理基于光的干涉现象。当光在薄膜上下界面反射并叠加时,会产生与厚度相关的干涉条纹。通过分析这些条纹,可以非接触、无损地获取薄膜的精确厚度信息。这项技术的核心价值在于实现了对关键工艺参数的在线、快速监控,对于提升器件性能与生产良率至关重要。在第三代半导体,尤其是碳化硅功率器件的制造中,外延层厚度直接决定了器件的击穿电压和导通电阻等核心性能。红外干涉光谱法因其对碳化硅材料在红外波段的良好透过性,成为该领域主流的厚度测量方案。通过快速傅里叶变换(FFT)对采集到

weixin_29032489的博客 309

PyTorch可视化 | 可视化网络结构 | 使用TensorBoard可视化训练过程

PyTorch可视化

liujiesxs的博客 4517

项目安全等保测评加固手册

安全等级测评的目的是通过对目标系统在安全技术及管理方面的测评,对目标系统的安全技术状态及安全管理状况做出初步判断,给出目标系统在安全技术及安全管理方面与其相应安全等级保护要求之间的差距。测评结论作为委托方进一步完善系统安全策略及安全技术防护措施依据!!

菜鸟运维升级之路 2419

pytorch可视化之:可视化网络结构+CNN可视化+TensorBorad使用

本节主要包括了pytorch可视化的学习,包括可视化网络结构,CNN可视化,使用tensorboard进行可视化的各种实现形式以及代码测试。

weixin_52836217的博客 5784

雷达信号处理——恒虚警检测(CFAR)

上图展示的是同时在距离维和多普勒维进行恒虚警检测的原理,如果只是在距离维或多普勒维做CFAR,检测单元的左右两侧均有设定好数量的保护单元和参考单元。不同的CFAR检测器适用于不同的场景,CA-CFAR算法适用于均匀环境中的单目标或彼此相距较远的多目标环境,在邻近多目标环境会发生目标的遮蔽效应,在杂波边缘会发生杂波边缘效应。从图中也可以看到,根据阈值的选择不同,有不同的检测器,其中CA-CFAR是取的参考单元的均值,SO-CFAR取的是参考单元的最小值,而GO-CFAR是取的参考单元的最大值。

诚朴勇毅 3万+

紫光展锐面试——FPGA/IC设计面试面经案例总结

自我介绍;研究生的主要研究方向是什么?为什么想要应聘数字芯片相关的工作?简单介绍下数字IC设计流程。逻辑综合主要做什么?你有实际做过逻辑综合工作吗?你了解SS corner和FF corner吗?综合时应该使用哪个corner?综合时需要考虑hold吗?为什么?提高时钟频率对setup和hold有什么影响?为什么?hvt、rvt/svt、lvt有什么区别?c40、c50是指什么概念?有什么区别?你对EDA工具有过了解吗?

FPGA/MATLAB学习教程/源码/项目合作开发 1565

Pytorch 网络结构的可视化

在使用Pytorch时,常用的模型可视化法方法

齐落山大勇的博客 935

Windows11 - Ubuntu 双系统及 ROS、ROS2 安装

在本教程中,我们将使用 Ubuntu 20.04 版本,该版本使用了新的 Ubuntu 桌面安装程序,该程序将包含在今后发布的所有 Ubuntu 版本中。如果你选择了这个选项,你会看到一个简单的界面,允许你选择要安装Ubuntu的硬盘,并通过滑块来决定你希望Ubuntu使用的磁盘空间大小。如果你的电脑有多个硬盘驱动器,那么只要它们各自有自己的驱动器,这个选项就能让你在安装 Ubuntu 的同时安装现有的操作系统。在此屏幕上,系统会提示您输入您的姓名和您的计算机名称,以显示在网络上。

机器人控制与仿真应用 4509

pytroch实战12:基于pytorch的网络结构可视化

pytroch实战12:基于pytorch的网络结构可视化

weixin_46676835的博客 3542

RV1126笔记二十七:MetaRTC6移植

MetaRTC6移植

6038

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

pytorch使用(三)网络结构可视化

pytorch使用(三)网络结构可视化

修行记 2万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Pytorch的网络结构可视化(tensorboardX)(详细)

最近刚刚发现一个非常好用的显示模型神器Netron https://github.com/lutzroeder/Netron 借助这个工具可以像windows的软件一样导入已经训练好的模型加权重即可一键生成 我目前看了下visdom实现pytorch的网络结构查找还是很困难,在stackflow上有很多人使用自己编写的基于matplotlib来实现网络结构可视化适用性也不是很好,后来查找到使...

xiaoxifei的专栏 3万+

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Pytorch可视化(一)之网络结构可视化

我们可以看到torchinfo提供了更加详细的信息,包括模块信息(每一层的类型、输出shape和参数量)、模型整体的参数量、模型大小、一次前向或者反向传播需要的内存大小等,这样,我们就可以更直观、全面地理解模型结构,便于调试与优化。:只能在jupyter notebook中使用,要注意各安装包之间版本的匹配,输出的网络结构图比较直观,细节也相对丰富。:使用比较简单,但安装的时候必须做好版本匹配,需在浏览器中查看,相对来说不太好看,但细节比较丰富。:基于LaTeX的神经网络绘图工具,高清晰度的网络结构图。

typical_yyc的博客 902
上一篇: 浙大吴飞与贾扬清经典十问!
下一篇: 李沐:博士这五年
机器学习算法那些事
博客等级 码龄9年 1633粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值