当前位置:网站首页>Pytoch note57 pytoch visual network structure
Pytoch note57 pytoch visual network structure
2022-04-22 21:16:00 【Hyacinth's cat redamancy】
Pytorch Note57 Pytorch Visual network structure
List of articles
A summary of all notes : Pytorch Note Happy planet
With the development of deep neural network , The structure of the network is becoming more and more complex , It is also difficult to determine the input structure of each layer , Output structure, parameters and other information , This makes it difficult for us to finish in a short time debug. Therefore, it is necessary to master a tool that can be used to visualize the network structure . Similar functions are in another deep learning library Keras You can call one called model.summary() Of API It's easy to implement , After calling, our model parameters will be displayed , Input size , Output size , Overall parameters of the model, etc , But in PyTorch There is no such convenient tool to help us visualize our model structure .
about pytorch Come on , The visualization of model structure is still more important , This will facilitate our understanding of the data , And it can also deepen the understanding of the convolution change of each layer of data . Today's article briefly introduces , Visualization of some models , It's what I usually use to write code , It can also be used to check whether the code can output correctly .
Use print Print
In fact, the simplest thing is to use print Print , For example, we don't understand the official implementation of one of the networks , We can torchvision Import our model
I simply use torchvision Medium alexnet Model to test
from torchvision import models
net = models.alexnet()
print(net)
Then use it directly print Print , We can directly see the parameters of the internal implementation , We can use this to have a better understanding of our network model , We can also use these models for transfer learning , Just change the last level of classification .
AlexNet(
(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)
)
(avgpool): AdaptiveAvgPool2d(output_size=(6, 6))
(classifier): Sequential(
(0): Dropout(p=0.5, inplace=False)
(1): Linear(in_features=9216, out_features=4096, bias=True)
(2): ReLU(inplace=True)
(3): Dropout(p=0.5, inplace=False)
(4): Linear(in_features=4096, out_features=4096, bias=True)
(5): ReLU(inplace=True)
(6): Linear(in_features=4096, out_features=1000, bias=True)
)
)
But simple print(model), Only the information of basic components can be obtained , It can't show the of each layer shape, The size of the corresponding parameter quantity cannot be displayed ,
torchinfo visualization
In fact, a lot of what I used before were torchsummary, But it seems that ,torchsummary and torchsummaryX It hasn't been updated for a long time , and torchinfo By torchsummary and torchsummaryX The reconstructed Library .
And for ,torchsummary Sometimes it looks a little bloated , Output dimensions and quantities of all layers , The deep network structure is a little bloated .
install torchinfo perhaps torchsummary
This is very simple , Is the use pip Can be installed , Open the command line , Enter the following command to install
pip install torchinfo torchsummary
Use torchinfo
Whether it's for us torchinfo still torchsummary Come on , We all use the library summary function , However, the two parameters are somewhat different
You can also choose your preferences according to your preferences summary
First, we can use our torchinfo Of summary function
from torchvision import models
net = models.alexnet()
from torchinfo import summary
summary(model, (1, 3, 224, 224)) # 1:batch_size 3: The number of channels in the picture 224: The height and width of the picture

torchinfo Provides more detailed information , Include
-
Module information ( The type of each floor 、 Output shape And parameter quantities )

-
The parameter quantity and size of the whole model

-
Memory size required for a forward or reverse propagation, etc

We can also see the previous summary function , For this part , Namely Layer The visualization of is different , This part of visualization also gives many parameters , But for the results of complex models , It won't be clear
from torchsummary import summary
summary(net, (3, 224, 224)) # 3: The number of channels in the picture 224: The height and width of the picture

Be careful :
When using colab perhaps jupyter notebook when , Want to implement this method ,summary()It must be the unit ( namely notebook Medium cell) The return value of , Otherwise we need to useprint(summary(...))To visualize .
版权声明
本文为[Hyacinth's cat redamancy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221806064679.html
边栏推荐
- . net core add Middleware
- k8s部署mysql
- Freemodbus Quick Start Guide
- Time report填写规则
- 2022 question bank and online simulation examination of hoisting machinery command certificate
- LeetCode-238-除自身以外数组的乘积
- 【工具配置篇】Visual Studio 中由 designer 生成的. ui 文件未能及時更新問題的解决方案
- OpenVX-将Image文件[pgm格式]读写为vx_image对象,以及写操作
- select distinct语句 去重
- QT使用windeployqt.exe打包程序
猜你喜欢

Study record of the 8th week of graduation project

Analysis of tourism products: travel around
![[data cleaning and drawing] simple application of dataframe](/img/4b/aa119ada8d3267d180735fc2216bb9.png)
[data cleaning and drawing] simple application of dataframe

Basic design of character animation based on paogd

Four things we cannot do in media operation

Summary of software testing knowledge points | JMeter implementation Interface Association

Confidence interval and interval estimation

Spark-2.4.2编译安装

Selenium_Webdriver视频自动化脚本分享

OpenVX 的 立即模式(immediate mode)和图模式(graph mode)和示例讲解
随机推荐
[MySQL from introduction to mastery]: a summary of wildcards in common like clauses
SEREDS解串模块简介以及硬件实现
Brief introduction to common database engines
驱动开发总结记录
QT uses windeployqt Exe packaging program
2022-4-22 Leetcode 91.解码方法
QT使用windeployqt.exe打包程序
jmeter整套资料
ImportError: cannot import name ‘get_all_providers‘ from ‘onnxruntime.capi._pybind_state‘
Selenium_ Webdriver video automation script sharing
.bashrc . bash_ profile . bash_ logout . bash_ history
Force buckle - 64 Minimum path sum
Design and implementation of Snake game based on OpenGL
MySQL尚硅谷课程查缺补漏适合基础(一)
C randomly obtains one from list or string
Openvx's immediate mode and graph mode and examples
News Express I mobtech passed the "special safety evaluation" of China Academy of information and communications
2022-4-22 Leetcode 279.完全平方数
【工具配置篇】Visual Studio 中由 designer 生成的. ui 文件未能及时更新问题的解决方案
Confidence interval and interval estimation