Lite在Android上进行对象检测

Lite在Android上进行对象检测

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

问题描述

尝试使用Android Studio使用Tensorflow Lite实施自定义对象检测模型.我正在按照此处提供的指南进行操作:使用TensorFlow Lite ,但是没有成功.示例模型运行正常,显示了所有检测到的标签.但是,当我尝试使用自定义模型时,我根本没有得到任何标签.我也尝试了其他模型(从互联网上获取,但结果是相同的).就像标签没有以写入方式传递一样.我复制了 detect.tflite labelmap.txt ,并在中更改了 TF_OD_API_INPUT_SIZE TF_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上进行对象检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:55