5

I am trying to measure FLOPS for a TFLite model in TF2. I know that Tensorflow 1.x had the tf.profiler, which was awesome for measuring flops. It doesn't seem to work well with tf.keras.

Could anybody please describe how to measure FLOPs for a TFLite model in TF2? I can't seem to find an answer online. Thank you all so much for your time.

Edit: The link commented below does not help with tflite.

  • Does this answer your question? [TensorFlow: Is there a way to measure FLOPS for a model?](https://stackoverflow.com/questions/45085938/tensorflow-is-there-a-way-to-measure-flops-for-a-model) – Khalid Saifullah Jan 12 '21 at 10:28
  • Unfortunately, I don't think this works for TFLite. Do you know of any other way? Thank you. – David Bradford Jan 12 '21 at 12:32

2 Answers2

3

I encountered the same problem and wrote a simple python package to roughly calculate FLOPS.

https://github.com/lisosia/tflite-flops

Only Conv and DepthwiseConv layers are considered, but it was sufficient for my use case.

asao
  • 46
  • 3
2

Unfortunately, there's no direct way you can calculate the FLOPS for a tflite model. However, you can estimate its value indirectly, by following these 3 steps:

  1. Use the official TFLite performance tool to measure how long your model takes (in ms) to perform a single inference.
  2. Use some benchmark app (such as xOPS) to estimate how many floating-point operations per second (FLOPS) your target device can run.
  3. Use the results you got from steps 1 and 2 to estimate the number of floating-point operations your model performs during a single inference.

The final result will probably be a rough approximation, but it still can bring some value to your performance analysis.