当前位置:网站首页>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))
边栏推荐
- 当我们在看待产业互联网的时候,总是会站在消费互联网的对立面来看待它
- Torchdrug -- drug attribute prediction
- Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
- Lambda 表达式原理分析学习(2022.06.23)
- 正则系列之字符类
- Client请求外部接口标准处理方式
- VB的基本语法
- The former king of fruit juice sold for 1.6 billion yuan
- 传输层 使用滑动窗口实现流量控制
- 文件包含&条件竞争
猜你喜欢

RP原型资源分享-购物类App

Conditional compilation

CADD course learning (2) -- target crystal structure information

企业中台规划和IT架构微服务转型

更智能!AIRIOT加速煤炭行业节能减排升级
![[solved] how does Tiktok cancel paying attention to the cancelled account](/img/1f/7b0bd2c0f69f7f3d1c25c426cc5771.png)
[solved] how does Tiktok cancel paying attention to the cancelled account

Tencent conference application market was officially launched, with more than 20 applications in the first batch
![[try to hack] windows system account security](/img/2b/e6e999313e3ae4e1cbf4bfa02daef0.png)
[try to hack] windows system account security
Redis ziplist 压缩列表的源码解析

4.3寸触控屏12路控制端口可编程网络中控支持5台中控主机相互备份
随机推荐
discuz 论坛提速之删除data/log下的xxx.php文件
【NLP】【TextCNN】 文本分类
腾讯会议应用市场正式上线,首批入驻超20款应用
Conditional compilation
Audio and video architecture construction in the super video era | science and Intel jointly launched the second season of "architect growth plan"
条件编译
c语言数组截取,C# 字符串按数组截取方法(C/S)
GeoServer安装
pytorch实现FLOPs和Params的计算
《微信小程序-基础篇》带你了解小程序中的生命周期(二)
Perl转换文件的编码类型
SM2246EN+闪迪15131
CADD课程学习(1)-- 药物设计基础知识
为什么一定要从DevOps走向BizDevOps?
Graduates
Go语言学习教程(十三)
暑期实训21组第一周个人工作总结
[try to hack] windows system account security
Network planning | [five transport layers and six application layers] knowledge points and examples
qt中toLocal8Bit和toUtf8()有什么区别