当前位置:网站首页>Pytorch implements the calculation of flops and params
Pytorch implements the calculation of flops and params
2022-06-30 20:11:00 【Haohao+++】
Concept
- FLOPS: Refers to the number of floating-point operations per second , It means computing speed , Is a measure of hardware performance .
Calculation formula :
For convolution :(K_h * K_w * C_in * C_out) * (H_out * W_out)
For the full connectivity layer :C_in * C_out
- FLOPs: Be careful s A lowercase letter , Refers to a floating-point operand , It means the amount of calculation . It can be used to measure the algorithm / The complexity of the model .
- Params: It refers to the total number of parameters to be trained in model training .
The calculation formula of model parameters is :
For convolution :(K_h * K_w * C_in)* C_out
For the full connectivity layer :C_in * C_out
Code implementation
Method 1
Use thop library
pip install thop
import torch
from torchvision import models
from thop import profile
if __name__ == '__main__':
net = models.mobilenet_v2()
inputs = torch.randn(1, 3, 224, 224)
flops, params = profile(net, inputs=(inputs, ))
print("FLOPs=", str(flops/1e9) +'{}'.format("G"))
print("params=", str(params/1e6)+'{}'.format("M"))
Method 2
Use torchstat library
pip install torchstat
import torch
from torchvision import models
from torchstat import stat
if __name__ == '__main__':
net = models.mobilenet_v2()
stat(net, (3, 224, 224))
边栏推荐
- 静态类使用@Resource注解注入
- Client请求外部接口标准处理方式
- 启动PHP报错ERROR: [pool www] cannot get uid for user ‘@[email protected]’
- Transport layer uses sliding window to realize flow control
- 【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline
- arthas调试 确定问题工具包
- exness:美GDP终值意外加速萎缩1.6%
- yolo 目标检测
- Why should offline stores do new retail?
- CADD课程学习(2)-- 靶点晶体结构信息
猜你喜欢

CADD course learning (1) -- basic knowledge of drug design

mysql统计账单信息(上):mysql安装及客户端DBeaver连接使用

CV+Deep Learning——网络架构Pytorch复现系列——basenets(BackBones)(一)

Tencent conference application market was officially launched, with more than 20 applications in the first batch

【Try to Hack】Windows系统账户安全
MySQL数据库误删回滚的解决

NLP技能树学习路线-(一)路线总览

传输层 使用滑动窗口实现流量控制

Tensorflow2.4实现RepVGG

项目经理是领导吗?可以批评指责成员吗?
随机推荐
Unity 如何拖拉多个组件中的一个
Network planning | [five transport layers and six application layers] knowledge points and examples
Graduates
十分之坑,tar命令解压文件的时候竟然不能解析英文括号“()”
6-1漏洞利用-FTP漏洞利用
Application of JDBC in performance test
Kubernetes为什么会赢,容器圈的风云变幻!
【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline
Spark - 一文搞懂 Partitioner
Playwright - 滚动条操作
mysql统计账单信息(上):mysql安装及客户端DBeaver连接使用
DELL R720服务器安装网卡Broadcom 5720驱动
QQmlApplicationEngine failed to load component qrc:/main.qml:-1 No such file or directory
静态类使用@Resource注解注入
新出生的机器狗,打滚1小时后自己掌握走路,吴恩达开山大弟子最新成果
Tensorflow2.4实现RepVGG
How unity pulls one of multiple components
Which brokerage has the lowest commission? In addition, is it safe to open a mobile account?
discuz 论坛提速之删除data/log下的xxx.php文件
Data intelligence - dtcc2022! China database technology conference is about to open