1

我想知道是否可以使用 ML Kit 在 android studio 中实现一个暗网模型(yolov4-tiny)转换为 .tflite。我尝试使用此存储库:https ://github.com/googlesamples/mlkit/tree/master/android/vision-quickstart ,但是当我替换为我的自定义对象检测模型时,应用程序返回此错误:无法处理. 错误:无法初始化检测器。输入张量的类型为 kTfliteFloat32:它需要指定 NormalizationOptions 元数据来预处理输入图像。原因:空。 你能给我一个建议吗?请。我正在尝试实时计算对象,我认为 ML 套件是跟踪和计算对象而不重复的唯一方法。先感谢您。

4

2 回答 2

0

您是否尝试使用 ML Kit自定义对象检测和跟踪功能?对于该功能,支持的自定义模型是分类器模型,而不是检测器模型。您可以在https://developers.google.com/ml-kit/custom-models中找到更多详细信息

于 2021-03-23T17:55:09.423 回答
-1

您可以运行此代码来修复此错误

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 = "yolo_without_metadata.tflite"
# Task Library expects label files that are in the same format as the one below.
_LABEL_FILE = "labelmap.txt"
_SAVE_TO_PATH = "yolo_with_metadata.tflite"
# Normalization parameters is required when reprocessing the image. It is
# optional if the image pixel values are in range of [0, 255] and the input
# tensor is quantized to uint8. See the introduction for normalization and
# quantization parameters below for more details.
# https://www.tensorflow.org/lite/convert/metadata#normalization_and_quantization_parameters)
_INPUT_NORM_MEAN = 127.5
_INPUT_NORM_STD = 127.5

# Create the metadata writer.
writer = ObjectDetectorWriter.create_for_inference(
    writer_utils.load_file(_MODEL_PATH), [_INPUT_NORM_MEAN], [_INPUT_NORM_STD],
    [_LABEL_FILE])

# Verify the metadata generated by metadata writer.
print(writer.get_metadata_json())

# Populate the metadata into the model.
writer_utils.save_file(writer.populate(), _SAVE_TO_PATH)
于 2021-06-02T13:45:48.370 回答