FLOPS: 全大写,指每秒浮点运算次数,可以理解为计算的速度。是衡量硬件性能的一个指标。(硬件)
FLOPs: s小写,指浮点运算数,理解为计算量。可以用来衡量算法/模型的复杂度。(模型) 在论文中常用GFLOPs(1 GFLOPs = 10^9 FLOPs)
2017年,ICIR收录了NVIDIA发表的一篇论文,在这篇论文的附录里,NVIDIA详细的讲解了一下FLOPs的计算。

对于卷积层来说:

有人将其简化了一下:

感兴趣的同学可以移步CNN模型所需的计算力(flops)和参数(parameters)数量是怎么计算的? - 知乎
在此推荐一个神器(pytorch):torchstat
可以用来计算pytorch构建的网络的参数,空间大小,MAdd,FLOPs等指标,简单好用。
比如:我想知道alexnet的网络的一些参数。
只需要:
from torchstat import stat
import torchvision.models as models
model = model.alexnet()
stat(model, (3, 224, 224))
就能得到结果啦:

可以看到每一层都有结果!兼职是神器呀。
再附上一个常用网络的参数:

来源:https://github.com/sovrasov/flops-counter.pytorch
以及:

跑的有点远,收!

作者认为FLOPs是一种简介的测量指标,是一个近似值,并不是我们真正关心的。我们需要的是直接的指标,比如速度和延迟。

图c是经典小网络在GPU上的MFLOPs与速度(Batches/sec)的关系。 图d是经典小网络在ARM上的MFLOPs与速度(Batches/sec)的关系。
我们可以发现,具有相似的FLOPs的网络,执行的速度却不一样。有的相差还挺大。
使用FLOP作为计算复杂度的唯一指标是不充分的。
为什么不能只用FLOPs作为指标呢?
作者认为有如下几个原因:
-
FLOPs没有考虑几个对速度有相当大影响的重要因素。 2)计算平台的不同。
-
FLOPs没有考虑几个对速度有相当大影响的重要因素
MAC和并行度
具体参见这篇文章: 轻量级神经网络“巡礼”(一)—— ShuffleNetV2
网友评论