欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

如何将tensorflow程序移植到手机APP

程序员文章站 2024-01-24 20:03:04
...

首先,我们先介绍tensorflow上提供的demo。
我们这里用Bazel。

一.下载tensorflow。

git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git

二.安装Bazel。安装教程:

https://docs.bazel.build/versions/master/install.html

三.安装NDK。只需下载解压即可。注意,这里最好下载12版本的。其他版本亲测,会出错。

https://developer.android.com/ndk/downloads/older_releases.html#ndk-12b-downloads

四.安装SDK。SDK可以单独安装,但是我们这里直接安装Android stdio ,然后会提示我们安装SDK。下载方法:

https://developer.android.com/studio/index.html

五.修改workspace文件

# Uncomment and update the paths in these entries to build the Android demo.
android_sdk_repository(
    name = "androidsdk",
    api_level = 26,
    # Ensure that you have the build_tools_version below installed in the
    # SDK manager as it updates periodically.
    build_tools_version = "26.0.1",
    # Replace with path to Android SDK on your system
    path = "/home/no1/Android/Sdk/",
)
#
# Android NDK r12b is recommended (higher may cause issues with Bazel)
android_ndk_repository(
    name="androidndk",
    path="/home/no1/android-ndk-r12b/",
    # This needs to be 14 or higher to compile TensorFlow.
    # Please specify API level to >= 21 to build for 64-bit
    # archtectures or the Android NDK will automatically select biggest
    # API level that it supports without notice.
    # Note that the NDK version is not the API level.
    api_level=26)

六.编译:

bazel build -c opt //tensorflow/examples/android:tensorflow_demo

如果出错则换用这个指令:

bazel build --noincremental_dexing //tensorflow/examples/android:tensorflow_demo

完成之后:出现如下情况表示编译完成:
如何将tensorflow程序移植到手机APP

然后在目录:tensorflow/bazel-bin/tensorflow/examples/android 下找到我们想要的apk,传到手机上,安装之后,可以看到有四个小功能的APP

相关标签: app tensorflow