首页 > 解决方案 > ModuleNotFoundError:没有名为“tflite_support.metadata_writers”的模块

问题描述

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

要查看安装一些常见依赖项的示例,请单击下面的 “打开示例”按钮。

如何修复这个错误?

标签: tensorflowmodelmetadataobject-detectiontensorflow-lite

解决方案


您必须通过以下方式安装

!pip install tflite_support

这仅在每晚(https://github.com/tensorflow/tensorflow/issues/26422)中受支持,因此通过安装

!pip install tflite_support_nightly

推荐阅读