from tflite_support.metadata_writers import object_detector
from tflite_support.metadata_writers import writer_utils
from tflite_support import metadata
ObjectDetectorWriter = object_detector.MetadataWriter
_MODEL_PATH = "mobile.tflite"
_LABEL_FILE = "labelmap.txt"
_SAVE_TO_PATH = "detect_metadata.tflite"
writer = ObjectDetectorWriter.create_for_inference(
writer_utils.load_file(_MODEL_PATH), [127.5], [127.5], [_LABEL_FILE])
writer_utils.save_file(writer.populate(), _SAVE_TO_PATH)
# Verify the populated metadata and associated files.
displayer = metadata.MetadataDisplayer.with_model_file(_SAVE_TO_PATH)
print("Metadata populated:")
print(displayer.get_metadata_json())
print("Associated file(s) populated:")
print(displayer.get_packed_associated_file_list())
我使用了以下链接Github:https://github.com/tensorflow/tensorflow/issues/43775中的代码
但这段代码是个bug。以下是运行上述代码后出现的错误。
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-87-39fd915e7a2a> in <module>()
----> 1 from tflite_support.metadata_writers import object_detector
2 from tflite_support.metadata_writers import writer_utils
3 from tflite_support import metadata
4
5 ObjectDetectorWriter = object_detector.MetadataWriter
ModuleNotFoundError:没有名为“tflite_support.metadata_writers”的模块
注意:如果您的导入由于缺少包而失败,您可以使用!pip
或!apt
手动安装依赖项。
要查看安装一些常见依赖项的示例,请单击下面的“公开的例子”按钮。
如何修复这个bug?
发布于 2021-05-11 04:27:50
你必须安装了
!pip install tflite_support
这只在夜间(https://github.com/tensorflow/tensorflow/issues/26422)中被支持,所以请通过
!pip install tflite_support_nightly
发布于 2022-09-15 13:45:47
pypi上的tflite_support包现在包括了tflite_support.task
但是,它不会在Python3.6上运行。版本0.3.1是支持Python3.6的最新版本。使用Python3.7而不是3.6,然后安装Verison0.4.2的tflite_support为我解决了问题。
https://stackoverflow.com/questions/67483995
复制