一、MACs 和 FLOPs 有什么区别?

FLOPs is abbreviation of floating operations which includes mul / add / div … etc.

MACs stands for multiply–accumulate operation that performs a <- a + (b x c).12

二、如何计算?

安装thop

pip install thop

pytorch使用thop:3

from torchvision.models import resnet50
from thop import profile
model = resnet50()
input = torch.randn(1, 3, 224, 224)
macs, params = profile(model, inputs=(input, ))

三、MACs 和 FLOPs的关系

粗略的:4,1,5

FLOPs = 2 * MACs

  1. https://github.com/Lyken17/pytorch-OpCounter/tree/master/benchmark#macs-flops-what-is-the-difference ↩︎ ↩︎

  2. https://github.com/Lyken17/pytorch-OpCounter/issues/46 ↩︎

  3. https://github.com/Lyken17/pytorch-OpCounter ↩︎

  4. https://zhuanlan.zhihu.com/p/364543528 ↩︎

  5. https://github.com/sovrasov/flops-counter.pytorch/issues/16 ↩︎

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐