测试网络模型的FLOPs和params

概念

FLOPS:注意全大写,是floating point operations per second的缩写,意指每秒浮点运算次数,理解为计算速度。是一个衡量硬件性能的指标。

FLOPs:注意s小写,是floating point operations的缩写(s表复数),意指浮点运算数,理解为计算量。可以用来衡量算法/模型的复杂度。

单位换算

1 MFLOPs(mega) = 10^6 FLOPs,即:100万次浮点运算

1 GFLOPs(giga) = 10^9 FLOPs,即:10亿次浮点运算

1 TFLOPs(tera) = 10^12 FLOPs,即:1万亿次浮点运算

参考链接:
https://zhuanlan.zhihu.com/p/541165764

代码:

import torch
from Net.MyNet import MyNet as net
from thop import profile
from thop import clever_format


model = net()
input = torch.rand(1,3,352,352)
input = input.cuda()
flops, params = profile(model, inputs=(input,))
flops, params = clever_format([flops, params], '%.3f')

print('模型参数:'params)
print('每一个样本浮点运算量:',flops)

猜你喜欢

转载自blog.csdn.net/holly_Z_P_F/article/details/132178080