tensorflow - 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
。
要查看安装一些常见依赖项的示例,请单击下面的 “打开示例”按钮。
如何修复这个错误?
解决方案
您必须通过以下方式安装
!pip install tflite_support
这仅在每晚(https://github.com/tensorflow/tensorflow/issues/26422)中受支持,因此通过安装
!pip install tflite_support_nightly
推荐阅读
- javascript - 单击时,单击另一个按钮不起作用。目标按钮是数据目标类型的按钮
- reactjs - 用户输入后立即添加一个附加组件
- javascript - 简单任务的问题:JavaScript 中的条件语句
- reactjs - 结合 .map 函数的事件处理
- vue.js - 如何模拟故事书故事中的模块?
- flutter - 颤振 | Dart - NoSuchMethodError:在 null 上调用了方法“map”
- javascript - 使用 Python 和 Javascript 在 CSV 中转换 HTML
- vim - 如何将 Mac OS X 终端设置为 VScode?
- google-cloud-automl - 设置访问 Google AutoML Vision 特定数据集的角色条件
- google-apps-script - 谷歌表格 - 发布日期和编辑它的用户名