【问题标题】:Not able to convert tf model into tflite model无法将 tf 模型转换为 tflite 模型
【发布时间】:2021-02-13 21:26:16
【问题描述】:

我尝试了很多方法,但无法将保存的模型文件转换为 tf lite 模型,每次运行新代码时都会出现不同的错误。从形状错误到下面列出的错误。

 File "C:\\models\py\lib\site-packages\tensorflow\python\eager\monitoring.py", line 407, in __del__
AttributeError: 'NoneType' object has no attribute 'TFE_MonitoringDeleteBuckets'

我正在使用此代码:

import tensorflow as tf


 #Convert the model
converter = tf.lite.TFLiteConverter.from_saved_model('new_graph/saved_model') # path to the SavedModel directory
tflite_model = converter.convert()



 #Save the model.
with open('facemask_model.tflite', 'wb') as f:
 tf.write(tflite_model)

谁能告诉我如何转换成 tf lite 模型,我在这里卡了几天

【问题讨论】:

    标签: python tensorflow keras model google-colaboratory


    【解决方案1】:

    我最近遇到了同样的问题,这似乎是最近 tf-nightly 版本中的一个错误。例如,您可以如下重现该错误。

    Python 3.7.9 (default, Aug 31 2020, 12:42:55)
    [GCC 7.3.0] :: Anaconda, Inc. on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    2020-10-21 13:48:47.162423: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
    >>>
    >>> exit()
    Exception ignored in: <function Buckets.__del__ at 0x7f8b017e2830>
    Traceback (most recent call last):
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/tensorflow/python/eager/monitoring.py", line 407, in __del__
    AttributeError: 'NoneType' object has no attribute 'TFE_MonitoringDeleteBuckets'
    

    请尝试版本 2.4.0.dev20200901。该版本将消除该错误。希望对大家有帮助,谢谢。

    【讨论】:

      【解决方案2】:

      您的模型似乎包含的不仅仅是内置的 TFLite 操作。您可以尝试使用 SELECT_TF_OPS 吗?

      https://www.tensorflow.org/lite/guide/ops_select

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-27
        • 2019-09-05
        • 1970-01-01
        • 2019-07-21
        • 1970-01-01
        相关资源
        最近更新 更多