Model Flops measurement in TensorFlow

zong fan
zong fan
Mar 28 · 1 min read

Calculating how much computing power needed to deploy a model is a quite meaningful and common requirement under actual industry production environment, especially for those edge computing applications. For the purpose of minimizing the cost and maximizing usage of computing devices or chips, we usually buy device whose capability just satisfies the basic performance requirement for the model with redundancy. Thanks to powerful community and abundant function module, TensorFlow has provided a fairly easy way to measure model Flops with tf.profiler .

Normally, we just measure frozen model which is used for inference only. What tf.profiler do is to calculate all operations in given graph.


If input node is a tf.placeholder, it will cause incomplete shape error. So we need replace the tf.placeholder node with other data type like tf.constant. For example, in TensorFlow object detection api, we can replace this line during freezing model with the following one.

input_tensor = tf.ones(shape=input_shape, dtype=tf.uint8, name='image_tensor')


zong fan

Written by

zong fan

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade