使用TensorFlow计算出的ResNet50的FLOP少于其论文中指示的数量

问题描述

我正在使用TensorFlow 2.3使用以下代码来计算resnet50的FLOP:

import tensorflow as tf

def get_flops(model_h5_path):
    session = tf.compat.v1.Session()
    graph = tf.compat.v1.get_default_graph()
        

    with graph.as_default():
        with session.as_default():
            model = tf.keras.models.load_model(model_h5_path)

            run_Meta = tf.compat.v1.RunMetadata()
            opts = tf.compat.v1.profiler.ProfileOptionBuilder.float_operation()
        
            # We use the Keras session graph in the call to the profiler.
            flops = tf.compat.v1.profiler.profile(graph=graph,run_Meta=run_Meta,cmd='op',options=opts)

IMG_SHAPE = (224,224,3)

model = tf.keras.applications.resnet50(input_shape=IMG_SHAPE,include_top=True,weights=None)
model.save('path_to_my_model.h5')
tf.compat.v1.reset_default_graph()
print(get_flops('path_to_my_model.h5'))

我的代码计算出它包含1.2亿个FLOP,但是paper表示resnet50包含38亿个FLOP。所以我的疑问是,我是用错误的方式计算出来的,还是TensorFlow的resnet50包含的FLOP更少?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)