web-dev-qa-db-ja.com

CNNでネットのフロップを計算する方法

GPUリソ​​ースを占有するたたみ込みニューラルネットワークをAlexnetだけで設計したいのですが、FLOPを使用して測定したいのですが、計算方法がわかりません。それを行うためのツールはありますか?

13
StalkerMuse

オンラインツールについては http://dgschwend.github.io/netscope/#/editor を参照してください。 alexnetについては http://dgschwend.github.io/netscope/#/preset/alexnet を参照してください。これは、最も広く知られているレイヤーをサポートします。カスタムレイヤーの場合は、自分で計算する必要があります。

9
lnman

将来の訪問者のために、KerasとTensorFlowをバックエンドとして使用する場合、次の例を試すことができます。 MobileNetのフロップを計算します。

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))
8
Tobias Scheck

Kerasを使用している場合は、このプルリクエストでパッチを使用できます: https://github.com/fchollet/keras/pull/62

次に、print_summary()を呼び出すと、レイヤーごとのフロップと合計の両方が表示されます。

Kerasを使用しない場合でも、フロップカウントを取得できるように、Kerasでネットを再作成する価値があります。

1
Alex I