How to calculate net flops in CNN

I want to create a convolutional neural network that takes up the GPU resource no more than Alexnet. I want to use FLOP to measure it, but I don’t know how to calculate it. Are there any tools for this?

+5
deep-learning neural-network caffe conv-neural-network
source share
3 answers

For an online tool, see http://dgschwend.imtqy.com/netscope/#/editor . For alexnet see http://dgschwend.imtqy.com/netscope/#/preset/alexnet . It supports the most widely known layers. For custom layers you will need to calculate yourself.

+4
source share

For future visitors, if you use Keras and TensorFlow as a Backend, you can try the following example. It computes FLOP for 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)) 
+1
source share

If you use Keras, you can simply use the patch in this pull request: https://github.com/fchollet/keras/pull/6203

Then just call print_summary () and you will see both the flops per layer and the total.

Even if you are not using Keras, it may be worth re-creating your networks in Keras so that you can count the number of flops.

0
source share

All Articles