当前位置: 首页 > 知识库问答 >
问题:

基于Tensorflow 2的Android目标检测

弘涛
2023-03-14

我正在尝试在Android上应用一个自定义的对象检测模型。为了应用该模型,我使用/lite/examples/object_detection下的tensorflow存储库示例。为此我也在使用我的个人手机(小米红米Note 8 pro,Android10)进行测试。该示例工作完美,能够识别不同的对象。但是,当我尝试导入自定义模型时,applycation会反复崩溃。为了运行我在build.gradle(:app)中添加了以下依赖项:

implementation('org.tensorflow:tensorflow-lite:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-support:0.0.0-nightly') { changing = true }

此外,我还用我的文件替换了detect.tflite和labelmap.txt。此外,我尝试更改DetectorActivity.java(TF_OD_API_INPUT_SIZE和TF_OD_API_IS_QUANZEED),因为我使用的模型(ssd_mobilenet_v2_fpnlite_640x640_coco17_tpu-8)具有不同的输入大小,但它仍然崩溃。有一个在移动上运行TF2检测API模型的指导,但我还没有设法实现什么。是我在Android上的程序做错了什么,还是模型出了问题?谢谢你!

我正在添加崩溃的Logcat输出:

2020-10-06 19:30:28.163 25354-25354/? E/mples.detectio: Unknown bits set in runtime_flags: 0x8000
2020-10-06 19:30:28.407 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2020-10-06 19:30:28.560 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.560 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.560 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.560 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.560 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.560 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.560 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.560 25354-25372/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.561 25354-25372/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.561 25354-25372/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.561 25354-25372/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "camera.aux.packagelist"
2020-10-06 19:30:28.626 25354-25354/org.tensorflow.lite.examples.detection E/GraphicExt: Can't load libboost_ext_fwk
2020-10-06 19:30:28.627 25354-25354/org.tensorflow.lite.examples.detection E/GraphicExt: GraphicExtModuleLoader::CreateGraphicExtInstance false
2020-10-06 19:30:28.642 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "vendor.debug.bq.dump"
2020-10-06 19:30:28.642 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "vendor.debug.bq.dump"
2020-10-06 19:30:28.642 25354-25354/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "vendor.debug.bq.dump"
2020-10-06 19:30:28.642 25354-25354/org.tensorflow.lite.examples.detection E/GraphicExt: GraphicExtModuleLoader::CreateGraphicExtInstance false
2020-10-06 19:30:28.657 25354-25354/org.tensorflow.lite.examples.detection E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.tensorflow.lite.examples.detection, PID: 25354
    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:116)
        at org.tensorflow.lite.examples.detection.DetectorActivity.onPreviewSizeChosen(DetectorActivity.java:99)
        at org.tensorflow.lite.examples.detection.CameraActivity$7.onPreviewSizeChosen(CameraActivity.java:446)
        at org.tensorflow.lite.examples.detection.CameraConnectionFragment.setUpCameraOutputs(CameraConnectionFragment.java:357)
        at org.tensorflow.lite.examples.detection.CameraConnectionFragment.openCamera(CameraConnectionFragment.java:362)
        at org.tensorflow.lite.examples.detection.CameraConnectionFragment.access$300(CameraConnectionFragment.java:66)
        at org.tensorflow.lite.examples.detection.CameraConnectionFragment$3.onSurfaceTextureAvailable(CameraConnectionFragment.java:171)
        at android.view.TextureView.getTextureLayer(TextureView.java:406)
        at android.view.TextureView.draw(TextureView.java:349)
        at android.view.View.updateDisplayListIfDirty(View.java:20568)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.updateDisplayListIfDirty(View.java:20559)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.updateDisplayListIfDirty(View.java:20559)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.draw(View.java:21740)
        at android.view.View.updateDisplayListIfDirty(View.java:20568)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1246)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.draw(View.java:21740)
        at android.view.View.updateDisplayListIfDirty(View.java:20568)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.updateDisplayListIfDirty(View.java:20559)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.updateDisplayListIfDirty(View.java:20559)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.updateDisplayListIfDirty(View.java:20559)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.updateDisplayListIfDirty(View.java:20559)
        at android.view.View.draw(View.java:21448)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4477)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4237)
        at android.view.View.draw(View.java:21740)
        at com.android.internal.policy.DecorView.draw(DecorView.java:844)
        at android.view.View.updateDisplayListIfDirty(View.java:20568)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:575)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:581)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:654)
2020-10-06 19:30:28.658 25354-25354/org.tensorflow.lite.examples.detection E/AndroidRuntime:     at android.view.ViewRootImpl.draw(ViewRootImpl.java:3877)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3668)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2988)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1888)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8043)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:969)
        at android.view.Choreographer.doCallbacks(Choreographer.java:793)
        at android.view.Choreographer.doFrame(Choreographer.java:728)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:954)
        at android.os.Handler.handleCallback(Handler.java:914)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7551)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)

更新:使用不同的设备(小米Redmi Note 4x,Android7),自定义应用程序可以工作,但无法识别带有bouding框的自定义对象。所以,对于我来说,Android10肯定有一个问题,对于第二种情况,我猜是与labelmap.txt文件有关(如果不是与训练好的模型有关的话)。

共有1个答案

彭硕
2023-03-14

为了回答我的问题,关于自定义对象检测模型实现的主要问题是没有一个应该附加到模型文件(在我的例子中是.tflite)的元数据文件。换句话说,一个描述和指定哪个是模型的文件,在android应用程序中输入图像的分辨率,您想要使用的标签文件等等(所以应用程序希望的是300x300分辨率,而不是我想要提供的640x640,这就是崩溃的原因)。要了解更多信息,您可以查看相关问题:这里。

 类似资料:
  • 我正在尝试使用以下命令评估我的模型: 我得到了这个错误 我得到了这个错误: Traceback(最近一次调用):文件"eval.py",第142行,在tf.app.run()文件"C:\用户\mosta\Anaconda3\envs\matt\lib\site-包\tensorflow_core\python\平台\app.py",第40行,在运行_run(main=Main, Argv=Argv

  • @subpage tutorial_py_face_detection_cn 人脸识别 使用 haar-cascades

  • 我正在尝试使用opencv 4 android sdk检测矩形文档。首先,我试图通过查找轮廓来检测它,但它不适用于多色文档。您可以查看此链接以获得更好的想法:使用OpenCV4Android检测多色文档 我做了很多研究,发现可以用houghline变换来完成。所以我按照以下方法检测文档: 原始图像- 我对hough线变换所做的是: 从上面的水平线和垂直线列表中,我找到了以下交叉点: 从这四个交点我

  • 本文向大家介绍Opencv基于CamShift算法实现目标跟踪,包括了Opencv基于CamShift算法实现目标跟踪的使用技巧和注意事项,需要的朋友参考一下 CamShift算法全称是“Continuously Adaptive Mean-Shift”(连续的自适应MeanShift算法),是对MeanShift算法的改进算法,可以在跟踪的过程中随着目标大小的变化实时调整搜索窗口大小,对于视频序

  • 在“锚框”一节中,我们在实验中以输入图像的每个像素为中心生成多个锚框。这些锚框是对输入图像不同区域的采样。然而,如果以图像每个像素为中心都生成锚框,很容易生成过多锚框而造成计算量过大。举个例子,假设输入图像的高和宽分别为561像素和728像素,如果以每个像素为中心生成5个不同形状的锚框,那么一张图像上则需要标注并预测200多万个锚框($561 \times 728 \times 5$)。 减少锚框

  • 我有一个2维数组叫做,也就是32x32。每个元素表示清除路径,表示墙。 窗口分辨率为800x800,这意味着