当前位置:网站首页>深度学习模型训练前的必做工作:总览模型信息
深度学习模型训练前的必做工作:总览模型信息
2022-08-10 05:29:00 【公众号学一点会一点】

在使用深度学习模型处理图像数据的时候,输入数据的大小在整个网络中是怎么变化的非常重要,但是如果只看代码的话,我们算起来比较麻烦,比如我们经过了各种上采样、下采样等,中间过程可能有几十个网络层,算过来算过去一来是麻烦,二来是不清晰明了。
今天介绍一个用来查看模型概览信息的包,对新手学习非常有帮助! 这就是torchsummary
包(https://github.com/sksq96/pytorch-summary)。
直接上用法。
安装
安装没什么难的,直接用pip即可。
pip install torchsummary
搭建模型
根据自己的需求进行模型的搭建。
模型总体信息概览
比如我们搭建了下面一个网络:
class MyNet(nn.Module):
def __init__(self, inchannels):
super(SRCNN, self).__init__()
self.main = nn.Sequential(
nn.Conv2d(inchannels, 64, kernel_size=9, stride=(1, 1), padding=(4, 4)),
nn.BatchNorm2d(64),
nn.ReLU(),
nn.Conv2d(64, 32, kernel_size=1, stride=(1, 1), padding=(0, 0)),
nn.BatchNorm2d(32),
nn.ReLU(),
nn.Conv2d(32, 1, kernel_size=5, stride=(1, 1), padding=(2, 2))
)
def forward(self, x):
y = self.main(x)
return y
现在我们想看一下输入数据在网络中的大小变化,以及可学习参数的总数量等信息,那么只需要使用summary函数即可:
model = MyNet(inchannels=1).to('cuda')
summary(model, input_size=(1, 222, 222))
然后便可以得到如下信息:

从中可以看到整个模型的如下信息:
所有的layer 每个layer的输出尺寸(-1代表是可变的,这里是batchsize的大小) 每一层的参数量 总的参数量 总得可学习参数量和无需学习的参数量 占用空间的大小
有什么用?
目前,个人觉得有很多:
最直接的就是可以清楚地了解自己的网络结构; 在用卷积神经网络的时候可以用这个来调整kernel size和padding的尺寸,这样子就不用用公式算了; 可以来测试自己的模型是不是能跑通。。如果错了的话,上面的结果是出不来的。
参考
【1】https://openbase.com/python/torch-summary
【2】https://clay-atlas.com/us/blog/2020/05/13/pytorch-en-note-torchsummary/
本文由 mdnice 多平台发布
边栏推荐
- pytorch框架学习(9)torchvision.transform
- Jenkins 如何玩转接口自动化测试?
- Order table delete, insert and search operations
- FPGA工程师面试试题集锦11~20
- 基于Qiskit——《量子计算编程实战》读书笔记(一)
- Matlab simulation of multi-factor house price prediction based on BP neural network
- 【格式转换】将JPEG图片批量处理为jpg格式
- FPGA engineer interview questions collection 1~10
- Guys, the test in the idea uses FlinkCDC SQL to read Mysql data and write it into Kafka. The code creates
- FPGA engineer interview questions collection 31~40
猜你喜欢
OneFlow源码解析:算子指令在虚拟机中的执行
An article will help you understand what is idempotency?How to solve the idempotency problem?
pytorch框架学习(5)torchvision模块&训练一个简单的自己的CNN (二)
如何在报表控件FastReport.NET中连接XLSX 文件作为数据源?
pytorch框架学习(9)torchvision.transform
深度梳理:防止模型过拟合的方法汇总
【LeetCode】41. The first missing positive number
在yolov5的网络结构中添加注意力机制模块
基于Qiskit——《量子计算编程实战》读书笔记(五)
每周推荐短视频:探索AI的应用边界
随机推荐
FPGA engineer interview questions collection 21~30
一篇文章带你搞懂什么是幂等性问题?如何解决幂等性问题?
MongoDB 基础了解(一)
pytorch框架学习(5)torchvision模块&训练一个简单的自己的CNN (二)
Pony语言学习(一):环境配置(续)
How cursors work in Pulsar
25张炫酷交互图表,一文入门Plotly
Why are negative numbers in binary represented in two's complement form - binary addition and subtraction
FPGA工程师面试试题集锦11~20
An article will help you understand what is idempotency?How to solve the idempotency problem?
pytorch框架学习(2)使用GPU训练
summer preschool assignments
再肝3天,整理了90个 NumPy 例子,不能不收藏!
canvas canvas drawing clock
OneFlow源码解析:算子指令在虚拟机中的执行
Matlab simulation of multi-factor house price prediction based on BP neural network
Attention candidates for the soft exam! The detailed registration process for the second half of 2022 is coming!
Qiskit 学习笔记1
pygame学习计划(1)
树莓派入门(3)树莓派GPIO学习