Relationship between MACs (number of multiplication and addition operations) and FLOPs (number of floating point operations), onnx function calculation method

The relationship between MACs (multiply and add operations) and FLOPs (floating point operations) is indeed somewhat misunderstood.

The main reasons are:

1. In some cases, multiplication is counted as 2 FLOPs and addition is counted as 1 FLOPs.

2. But the more standard calculation is: multiplication and addition are both counted as 1 FLOPs. So according to different calculation methods, the relationship between MACs and FLOPs is:

1. If multiplication counts 2 FLOPs and addition counts 1 FLOPs, then MACs = 2 * FLOPs

2. If both multiplication and addition count 1 FLOPs, then MACs = FLOPs. In summary, the relationship between MACs and FLOPs depends on the calculation method, but a more standard approach is: MACs and FLOPs are a magnitude, and their values ​​are equal or approximately equal.

The reason why some people on the Internet say that they are twice related may be because they use the calculation method of multiplication calculation 2 FLOPs.

But this is not a standard calculation method.

Therefore, MACs and FLOPs can be regarded as equal, and both are indicators that reflect the computational complexity of the model.

There is no need to specifically convert it to twice the original size.

How to use onnx to visualize the network and use onnx-tool to automatically calculate the parameters of each layer.

import netron
import onnx
#from onnx import numpy_helper, helper
import onnx_tool
netron.start('../pretrained_models/100w_net.onnx')
# 加载ONNX模型
model = onnx.load('../pretrained_models/100w_net.onnx')
onnx_tool.model_profile('../pretrained_models/100w_net.onnx')

Guess you like

Origin blog.csdn.net/qq_40962125/article/details/134165808