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
但是这段代码是一个错误。下面是运行上面代码后的错误。
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
手动安装依赖项。
要查看安装一些常见依赖项的示例,请单击 "Open Examples"下面的按钮。
如何修复此错误?
最佳答案
您必须通过安装
!pip install tflite_support
这仅在夜间( https://github.com/tensorflow/tensorflow/issues/26422 )中受支持,因此通过安装
!pip install tflite_support_nightly
关于tensorflow - 模块未找到错误: No module named 'tflite_support.metadata_writers' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67483995/