Error-Input tensor has type kTfLiteFloat32: it requires specifying NormalizationOptions metadata to

 

 在Android中报错:

Input tensor has type kTfLiteFloat32: it requires specifying NormalizationOptions metadata to prepro

1.首先安装tflite_support:

pip install tflite_support

2.然后将自己的tflite文件重新转换一下: 

https://stackoverflow.com/questions/66727627/failed-to-initialize-detector-input-tensor-has-type-ktflitefloat32-ml-kit

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"
_MODEL_PATH = "/home/gyx/QR/qr_detect_model/convert_model/tflite/ssd_mobilenet_v2_quantized_300x300_uint8.tflite"
# Task Library expects label files that are in the same format as the one below.
_LABEL_FILE = "/home/gyx/QR/qr_detect_model/data_all/label_map.pbtxt"
# _SAVE_TO_PATH = "yolo_with_metadata.tflite"
_SAVE_TO_PATH = "/home/gyx/QR/qr_detect_model/convert_model/tflite/ssd_mobilenet_v2_quantized_300x300_uint8_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)

将转换好的文件放入Android中就不会报错了!

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值