当前位置:网站首页>Pytorch查看模型参数量和计算量
Pytorch查看模型参数量和计算量
2022-06-30 12:54:00 【mytzs123】
1、首先声明一个网络
使用torchsummary可以查看模型的参数,和输入输出尺寸,但不能看FLOPs。
import torchvision.models
import torch
import torchsummary
model = torchvision.models.vgg16(pretrained=False)
device = torch.device('cpu')
model.to(device)
torchsummary.summary(model.cuda(), (3, 224, 224))
2、pip install thop
可以显示总的FLOPs和参数量params,但不能显示每层的结构,有一些警告,但是没关系,因为relu是不参与计算参数量和FLOPs的。
import torchvision.models
import torch
from thop import profile
from thop import clever_format
import torchsummary
model = torchvision.models.vgg16(pretrained=False)
device = torch.device('cpu')
model.to(device)
myinput = torch.zeros((1, 3, 224, 224)).to(device)
flops, params = profile(model.to(device), inputs=(myinput,))
flops, params = clever_format([flops, params], "%.3f")
print(flops, params)
3、pip install torchstat
可以显示总的FLOPs和参数量params,也可能显示每层的结构。
import torchvision.models
import torch
from torchstat import stat
model = torchvision.models.vgg16(pretrained=False)
device = torch.device('cpu')
model.to(device)
stat(model.to(device), (3, 224, 224))
边栏推荐
- 一条查询SQL是如何执行的
- JS converts an array to a two-dimensional array based on the same value
- 这个编辑器即将开源!
- 一次 Keepalived 高可用的事故,让我重学了一遍它!
- JS 二维数组变一维数组的方法
- 一篇文章读懂关于企业IM的所有知识点
- ABAP toolbox v1.0 (with implementation ideas)
- 资源变现小程序开通流量主教程
- QT read / write excel--qxlsx worksheet display / hide status setting 4
- Prometheus 2.29.0 新特性
猜你喜欢
DeFi“钱从哪来”?一个大多数人都没搞清楚的问题
WTM重大更新,多租户和单点登录
我如何才能保护我的私钥?
正则系列之断言Assertions
[kali] Kali system, software update (with image source)
一文讲清楚什么是类型化数组、ArrayBuffer、TypedArray、DataView等概念
postman 自動生成 curl 代碼片段
WTM major updates, multi tenancy and single sign on
JMeter learning notes
RK356x U-Boot研究所(命令篇)3.2 help命令的用法
随机推荐
Golang foundation -- slicing several declaration methods
Hangzhou E-Commerce Research Institute: the official website (website) is the only form of private domain
Unity animator parameter
商品服务-平台属性
visualstudio 和sql
你想要的异常知识点都在这里了
幸运哈希竞猜系统开发(源码部署)趣投哈希游戏玩法开发(案例需求)
golang文件的写入、追加、读取、复制操作:bufio包的使用示例
【招聘(广州)】成功易(广州).Net Core中高级开发工程师
Mqtt ROS simulates publishing a custom message type
Prometheus 2.29.0 新特性
损失函数:DIOU loss手写实现
(8)JMeter元件详解之 Once only Controller 仅一次控制器
Motor control Clarke( α/β) Derivation of equal amplitude transformation
Rk356x u-boot Institute (command section) 3.2 usage of help command
JMeter learning notes
Knowledge dissemination cannot replace professional learning!
WTM重大更新,多租户和单点登录
深度长文探讨Join运算的简化和提速
顺应媒体融合趋势,中科闻歌携手美摄打造数智媒宣