FLOPS:
注意全大写,是floating point operations per second的缩写,意指每秒浮点运算次数,理解为计算速度。是一个衡量硬件性能的指标。
FLOPs:
注意s小写,是floating point operations的缩写(s表复数),意指浮点运算数,理解为计算量。可以用来衡量算法/模型的复杂度。
最近在研究模型的计算量,发现Pytorch有库可以直接计算模型的计算量,https://github.com/Swall0w/torchstat
所以需要一个一个Keras和Tensorflow可以用的,直接把Model接入到函数中,print一下就可以计算出FLOPs
对于计算量主要有Madds和MFlops两个概念。shufflenet的论文用的是Flops,Mobilenet用的是Madds,Flops应该是Madds的两倍,具体可参考
https://blog.csdn.net/shwan_ma/article/details/84924142
https://www.zhihu.com/question/65305385/answer/451060549`
import tensorflow as tf
import keras.backend as K
def get_flops(model):
run_meta = tf.RunMetadata()
opts = tf.profiler.ProfileOptionBuilder.float_operation()
# We use the Keras session graph in the call to the profiler.
flops = tf.profiler.profile(graph=K.get_session().graph,
run_meta=run_meta, cmd='op', options=opts)
return flops.total_float_ops # Prints the "flops" of the model.
# .... Define your model here ....
print(get_flops(model))