当前位置:网站首页>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))
边栏推荐
- yolo 目标检测
- 科大讯飞活跃竞赛汇总!(12个)
- 无线充U型超声波电动牙刷方案开发
- 将 EMQX Cloud 数据通过公网桥接到 AWS IoT
- 一文读懂目标检测:R-CNN、Fast R-CNN、Faster R-CNN、YOLO、SSD「建议收藏」
- Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
- How unity pulls one of multiple components
- Safe holidays without holidays, VR traffic makes children travel safely | Guangzhou Sinovel viewpoint
- SSM整合流程(整合配置、功能模块开发、接口测试)
- “更福特、更中国”拨云见日,长安福特王牌产品订单过万
猜你喜欢

Idle fish is hard to turn over

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

实现各种效果和功能的按钮,读这篇文章就够了

Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field

Abaqus 2022软件安装包和安装教程

History, selection strategy and in-depth evaluation of note taking software

FH6908A负极关断同步整流模拟低压降二极管控制IC芯片TSOT23-6超低功耗整流器 1w功耗 <100uA静态 替代MP6908

台湾SSS鑫创SSS1700替代Cmedia CM6533 24bit 96KHZ USB音频编解码芯片

8 - 函数

What is the difference between tolocal8bit and toutf8() in QT
随机推荐
英语没学好到底能不能做coder,别再纠结了先学起来
Wechat applets - basics takes you to understand the life cycle of applets (2)
Redis beginner to master 01
内存数据库如何发挥内存优势?
QQmlApplicationEngine failed to load component qrc:/main.qml:-1 No such file or directory
Filebeat自定义index和fields
条件编译
WeakSet
Transport layer uses sliding window to realize flow control
composer
将秒数转换为**小时**分钟
太湖 “中国健康农产品·手机直播万里行”走进太湖
Character class of regular series
Idle fish is hard to turn over
Simple usage of LinkedList (2022.6.13-6.19)
WordPress 博客使用火山引擎 veImageX 进行静态资源 CDN 加速(免费)
Detailed explanation of specific methods and steps for TCP communication between s7-1500 PLCs (picture and text)
超视频时代的音视频架构建设|Science和英特尔联袂推出“架构师成长计划”第二季
matlab 将三角剖分结果保存为STL文件
VR全景添加对比功能,让差异化效果展示更直观!