David Bradford
David Bradford

Reputation: 304

Measuring Flops for TFLite Model in Tensorflow 2.X

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.

Upvotes: 5

Views: 2738

Answers (2)

asao
asao

Reputation: 46

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.

Upvotes: 3

Michel Meneses
Michel Meneses

Reputation: 94

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.

Upvotes: 1

Related Questions