本文介绍了使用 Tensorflow Lite 在 Android 上进行对象检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 Android Studio 通过 Tensorflow Lite 实现自定义对象检测模型.我正在遵循此处提供的指导:在移动设备上运行TensorFlow Lite,但是没有成功.示例模型运行正常,显示所有检测到的标签.尽管如此,当我尝试使用我的自定义模型时,我根本没有得到任何标签.我也尝试过其他模型(来自互联网,但结果是一样的).就像标签没有以写方式传递一样.我复制了我的 detect.tflitelabelmap.txt,我更改了 TF_OD_API_INPUT_SIZETF_OD_API_IS_QUANTIZED>DetectorActivity.java 但仍然没有得到结果(检测到带有边界框和分数的类).

Trying to implement a custom object detection model with Tensorflow Lite, using Android Studio. I am following the guidance provided here: Running on mobile with TensorFlow Lite, however with no success. The example model runs properly showing all the detected labels. Nonetheless, when I try with my custom model I am not getting any labels at all. I have also tried with other models(from the internet but the outcome is the same). It is like that the labels are not being passed with the write way. I copied my detect.tflite and labelmap.txt, I changed the TF_OD_API_INPUT_SIZE and the TF_OD_API_IS_QUANTIZED in the DetectorActivity.java but still not getting results(detected class with a bounding box and a score).

Logcat 显示以下内容:

2020-10-11 18:37:54.315 31681-31681/org.tensorflow.lite.examples.detection E/HAL: PATH3 /odm/lib64/hw/gralloc.qcom.so
2020-10-11 18:37:54.315 31681-31681/org.tensorflow.lite.examples.detection E/HAL: PATH2 /vendor/lib64/hw/gralloc.qcom.so
2020-10-11 18:37:54.315 31681-31681/org.tensorflow.lite.examples.detection E/HAL: PATH1 /system/lib64/hw/gralloc.qcom.so
2020-10-11 18:37:54.315 31681-31681/org.tensorflow.lite.examples.detection E/HAL: PATH3 /odm/lib64/hw/gralloc.msm8953.so
2020-10-11 18:37:54.315 31681-31681/org.tensorflow.lite.examples.detection E/HAL: PATH2 /vendor/lib64/hw/gralloc.msm8953.so
2020-10-11 18:37:54.315 31681-31681/org.tensorflow.lite.examples.detection E/HAL: PATH1 /system/lib64/hw/gralloc.msm8953.so
2020-10-11 18:37:54.859 31681-31681/org.tensorflow.lite.examples.detection E/tensorflow: CameraActivity: Exception!
    java.lang.IllegalStateException: This model does not contain associated files, and is not a Zip file.
        at org.tensorflow.lite.support.metadata.MetadataExtractor.assertZipFile(MetadataExtractor.java:325)
        at org.tensorflow.lite.support.metadata.MetadataExtractor.getAssociatedFile(MetadataExtractor.java:165)
        at org.tensorflow.lite.examples.detection.tflite.TFLiteObjectDetectionAPIModel.create(TFLiteObjectDetectionAPIModel.java:118)
        at org.tensorflow.lite.examples.detection.DetectorActivity.onPreviewSizeChosen(DetectorActivity.java:96)
        at org.tensorflow.lite.examples.detection.CameraActivity.onPreviewFrame(CameraActivity.java:200)
        at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1157)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:165)
        at android.app.ActivityThread.main(ActivityThread.java:6375)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

如何进行检测?我是否需要与标签相关的附加文件(元数据),或者我做错了什么?上述案例是在 Android 7 设备上进行测试的.谢谢!

How can I take the detection? Do I need an additional file(metadata) relative with the labels or I am doing sth else wrong?The above case is tested with an Android 7 device. Thanks!

推荐答案

这是本文档未更新的问题.

This is an issue with this documentation specifically that wasn't updated.

主要问题是样本已更新为使用附加了元数据的模型到它,特别是嵌入作为模型资产的标签.

The main problem is that the sample was updated to use models with Metadata attached to it, specifically with the labels embedded as an asset of the model.

当您将标签文件添加到模型时,一切都应该正常工作.

When you add your labels file to the model, everything should just work.

这篇关于使用 Tensorflow Lite 在 Android 上进行对象检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:40