繁体   English   中英

使用用于 object 检测的元数据创建 tflite model

[英]create tflite model with metadata for object detection

pip install tflite_support_nightly

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 = "mypath.tflite"
_LABEL_FILE = "labelmap.txt"
_SAVE_TO_PATH = "mypath_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())

我尝试使用此代码使用元数据创建 tflite model。 但我得到了这个错误

The number of output tensors (1) should match the number of output tensor metadata (4)

我怎么解决这个问题??

基本上,object检测器API需要以下要求:

(1) 应该只有一个输入张量来表示未压缩的图像。

(2)位置、类别、分数、检测次数应该有四个output张量。

上述要求实际上反映了object检测任务。 链接中查看更多详细信息。

如果您在制作符合上述要求的 model 时遇到困难,我建议您使用来自 TF hub 或AutoML Vision Edge object 检测解决方案预训练模型

也可以在指南页面上查看更多详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM