[英]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())
I tried to create tflite model with metadat using this code.我尝试使用此代码使用元数据创建 tflite model。 But I got this error但我得到了这个错误
The number of output tensors (1) should match the number of output tensor metadata (4)
How can I solve this problem??我怎么解决这个问题??
Basically, the object detector API requires the following requirements:基本上,object检测器API需要以下要求:
(1) There should be only one input tensor for representing an uncompressed image. (1) 应该只有一个输入张量来表示未压缩的图像。
(2) There should be four output tensors for locations, classes, scores, and number of detection. (2)位置、类别、分数、检测次数应该有四个output张量。
The above requirements actually reflect the object detection tasks.上述要求实际上反映了object检测任务。 See more the details at the link .在链接中查看更多详细信息。
If you have a difficulty on crafting the model, that is qualified to the above requirements, I would suggest using the pretrained models from TF hub or AutoML Vision Edge object detection solution .如果您在制作符合上述要求的 model 时遇到困难,我建议您使用来自 TF hub 或AutoML Vision Edge object 检测解决方案的预训练模型。
See more the details at the guide page as well.也可以在指南页面上查看更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.