FLOPs全称是floating point operations的缩写,翻译过来是浮点运算数,理解为计算量,常用来衡量算法或深度学习模型的计算复杂度。
#浮点运行次数
#FLOPS:注意全大写,是floating point operations per second的缩写,意指每秒浮点运算次数,理解为计算速度。是一个衡量硬件性能的指标。
#FLOPs:注意s小写,是floating point operations的缩写(s表复数),意指浮点运算数,理解为计算量。可以用来衡量算法/模型的复杂度。
#In TF 2.x you have to use tf.compat.v1.RunMetadata instead of tf.RunMetadata
#To work your code in TF 2.1.0, i have made all necessary changes that are compliant to TF 2.x
import tensorflow as tf
#必须要下面这行代码
tf.compat.v1.disable_eager_execution()
print(tf.__version__)
#函数
def get_flops_params():
sess = tf.compat.v1.Session()
graph = sess.graph
flops = tf.compat.v1.profiler.profile(graph, options=tf.compat.v1.profiler.ProfileOptionBuilder.float_operation())
params = tf.compat.v1.profiler.profile(graph, options=tf.compat.v1.profiler.ProfileOptionBuilder.trainable_variables_parameter())
print('FLOPs: {}; Trainable params: {}'.format(flops.total_float_ops, params.total_parameters))
model = unet()
get_flops_params()
输出结果
> ======================End of Report==========================
FLOPs: 4570813; Trainable params: 2286108
参考链接:https://blog.csdn.net/jwen_/article/details/115840140