简体   繁体   English

Tensorflow 2.X 中 TFLite Model 的测量触发器

[英]Measuring Flops for TFLite Model in Tensorflow 2.X

I am trying to measure FLOPS for a TFLite model in TF2.我正在尝试测量 TF2 中 TFLite model 的 FLOPS。 I know that Tensorflow 1.x had the tf.profiler, which was awesome for measuring flops.我知道 Tensorflow 1.x 有 tf.profiler,它非常适合测量翻牌。 It doesn't seem to work well with tf.keras.它似乎不适用于 tf.keras。

Could anybody please describe how to measure FLOPs for a TFLite model in TF2?有人可以描述如何在 TF2 中测量 TFLite model 的 FLOPs 吗? 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.编辑:下面评论的链接对 tflite 没有帮助。

Unfortunately, there's no direct way you can calculate the FLOPS for a tflite model.不幸的是,没有直接的方法可以计算 tflite model 的 FLOPS。 However, you can estimate its value indirectly, by following these 3 steps:但是,您可以通过以下 3 个步骤间接估计其价值:

  1. Use the official TFLite performance tool to measure how long your model takes (in ms) to perform a single inference.使用官方TFLite 性能工具来测量您的 model 执行单次推理需要多长时间(以毫秒为单位)。
  2. Use some benchmark app (such as xOPS ) to estimate how many floating-point operations per second (FLOPS) your target device can run.使用一些基准应用程序(例如xOPS )来估计您的目标设备每秒可以运行多少次浮点运算 (FLOPS)。
  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.使用从步骤 1 和 2 中获得的结果来估计 model 在单次推理期间执行的浮点运算的数量。

The final result will probably be a rough approximation, but it still can bring some value to your performance analysis.最终结果可能是一个粗略的近似值,但它仍然可以为您的性能分析带来一些价值。

I encountered the same problem and wrote a simple python package to roughly calculate FLOPS.我遇到了同样的问题,写了一个简单的 python package 来粗略计算 FLOPS。

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

Only Conv and DepthwiseConv layers are considered, but it was sufficient for my use case.只考虑了 Conv 和 DepthwiseConv 层,但这对我的用例来说已经足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM