簡體   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