如何计算CNN中网络的FLOP

Sta*_*use 14 neural-network deep-learning caffe conv-neural-network

我想设计一个卷积神经网络,占用GPU资源不超过Alexnet.我想用FLOP来测量它但我不知道如何计算它.有什么工具可以做到吗?

lnm*_*man 9

有关在线工具,请参阅http://dgschwend.github.io/netscope/#/editor.对于alexnet,请参阅http://dgschwend.github.io/netscope/#/preset/alexnet.这支持大多数广为人知的图层.对于自定义图层,您必须自己计算.

  • 截至本评论发布之日,该网页 (http://dgschwend.github.io/netscope/#/preset/alexnet) 似乎并未显示 FLOps。所有 macc 条目都有 NaN (2认同)

小智 9

对于将来的访客,如果您使用Keras和TensorFlow作为后端,则可以尝试以下示例。它计算MobileNet的FLOP。

import tensorflow as tf
import keras.backend as K
from keras.applications.mobilenet import MobileNet

run_meta = tf.RunMetadata()
with tf.Session(graph=tf.Graph()) as sess:
    K.set_session(sess)
    net = MobileNet(alpha=.75, input_tensor=tf.placeholder('float32', shape=(1,32,32,3)))

    opts = tf.profiler.ProfileOptionBuilder.float_operation()    
    flops = tf.profiler.profile(sess.graph, run_meta=run_meta, cmd='op', options=opts)

    opts = tf.profiler.ProfileOptionBuilder.trainable_variables_parameter()    
    params = tf.profiler.profile(sess.graph, run_meta=run_meta, cmd='op', options=opts)

    print("{:,} --- {:,}".format(flops.total_float_ops, params.total_parameters))
Run Code Online (Sandbox Code Playgroud)