I'd like to know if it is possible to implement a darknet model (yolov4-tiny) converted to .tflite in android studio with ML Kit. I've tried to use this repository: https://github.com/googlesamples/mlkit/tree/master/android/vision-quickstart , but when I replace to my custom object detection model, application returns this error: Failed to process. Error: Failed to initialize detector. Input tensor has type kTfliteFloat32: it requires specifying NormalizationOptions metadata to preprocess input images. Cause:null. Could you give me an advice?, please. I'm trying to count objects in real time, I think ML kit is the only way to track and count objects without repeat. Thank you in advance.
You can run this code for fixing this bug
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With