无法将TF模型转换为TFLI模型

时间:2020-10-31 18:06:41

标签: python tensorflow keras model google-colaboratory

我尝试了很多方法,但是我无法将保存的模型文件转换为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模型,我在这里呆了几天

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

我最近遇到了同样的问题,这似乎是最新的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。该版本将不再包含该错误。希望对大家有帮助,谢谢。

相关问题