当前位置:网站首页>pytorch实现FLOPs和Params的计算
pytorch实现FLOPs和Params的计算
2022-06-30 19:33:00 【Haohao+++】
概念
- FLOPS:指每秒浮点运算次数,理解为计算速度,是一个衡量硬件性能的指标。
计算公式:
对卷积层:(K_h * K_w * C_in * C_out) * (H_out * W_out)
对全连接层:C_in * C_out
- FLOPs: 注意s小写,指浮点运算数,理解为计算量。可以用来衡量算法/模型的复杂度。
- Params:是指模型训练中需要训练的参数总数。
模型参数量计算公式为:
对卷积层:(K_h * K_w * C_in)* C_out
对全连接层:C_in * C_out
代码实现
方法1
使用thop库
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"))
方法2
使用torchstat库
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))
边栏推荐
猜你喜欢

盘点华为云GaussDB(for Redis)六大秒级能力

Conditional compilation

VR全景添加对比功能,让差异化效果展示更直观!
Detailed steps for Django to upload excel tables and write data to the database

QQmlApplicationEngine failed to load component qrc:/main.qml:-1 No such file or directory

更智能!AIRIOT加速煤炭行业节能减排升级

Transport layer uses sliding window to realize flow control
Source code analysis of redis ziplist compressed list

Primary school, session 3 - afternoon: Web_ xxe

笔记软件的历史、选择策略以及深度评测
随机推荐
MQ selection (2022.5.9-5.15)
【多线程】使用线程池、实现一个简单线程池
A necessary tool for testing -- postman practical tutorial
为什么数字化转型战略必须包括持续测试?
arthas调试 确定问题工具包
屏幕显示技术进化史
WeakSet
dataloader 源码_DataLoader
Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
#夏日挑战赛#【FFH】HarmonyOS手机遥控Dayu开发板相机
Buttons to achieve various effects and functions. Reading this article is enough
【1175. 质数排列】
太湖 “中国健康农产品·手机直播万里行”走进太湖
KubeVela 1.4:让应用交付更安全、上手更简单、过程更透明
Spark - 一文搞懂 Partitioner
2022 最新 JCR正式发布全球最新影响因子名单(前600名)
网易云签到可抽奖?那一年我能签到365天。不信?你看。
如何快速通过PMP考试?
[jetsonnano] [tutorial] [introductory series] [i] how to enable VNC sharing
4.3-inch touch screen 12 channel control port programmable network central control supports mutual backup of 5 central control hosts