简体   繁体   中英

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. 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:

(1) There should be only one input tensor for representing an uncompressed image.

(2) There should be four output tensors for locations, classes, scores, and number of detection.

The above requirements actually reflect the object detection tasks. 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 .

See more the details at the guide page as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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