使用TensorFlow在Android上进行物体检测

使用TensorFlow Android Inference Interface在Android上进行图像物体检测

不支持Camera2 API的手机也可以物体检测:https://github.com/lijiancheng0614/android-TFDetect

从TensorFlow源代码编译TensorFlow Android Camera Demo

参考 https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android/

使用Bazel编译

  1. 下载TensorFlow源代码

    git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
  2. 准备环境

    • 安装Bazel

    • 安装Android NDK,版本应与Bazel配合,见官网对应的版本

    • 安装Android SDK

    • 编辑tensorflow/WORKSPACE中NDK和SDK的路径

  3. 编译

    
    # From tensorflow
    
    bazel build -c opt //tensorflow/examples/android:tensorflow_demo
  4. 安装

    adb install -r bazel-bin/tensorflow/examples/android/tensorflow_demo.apk

使用Android Studio和Bazel编译

修改tensorflow/examples/android/build.gradle中Bazel的路径,直接用Android Studio导入tensorflow/examples/android/目录作为新的Android Studio项目。

不支持Camera2 API的手机

由于部分手机不支持Camera2 API,故需要把调用Camera2 API的代码去掉。

具体来说,把tracking部分的代码删掉,只做object detection,并更新相应画bounding box的代码,这样速度也有所加快。

详细代码见:https://github.com/lijiancheng0614/android-TFDetect

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章