日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Tensorflow Lite 编译

發布時間:2025/3/15 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tensorflow Lite 编译 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Google最近發布了Tensorflow Lite,并且提供了demo,雖然該demo可以使用bazel build –cxxopt=’–std=c++11’ //tensorflow/contrib/lite/java/demo/app/src/main:TfLiteCameraDemo命令成功編譯出來,但是文檔中并沒有提及如何純粹的編譯出動態庫,參考之前的一篇文章《當 Android 開發者遇見 TensorFlow》,這篇文章就簡單介紹一下如何編譯動態庫

clone 代碼

1git clone https://github.com/tensorflow/tensorflow.git

修改TensorFlow項目根下的WROKSPACE文件

將以下代碼反注釋

1234567891011121314151617181920# Uncomment and update the paths in these entries to build the Android demo.android_sdk_repository(name = "androidsdk",api_level = 23,# 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 systempath = "/Users/lizhangqu/AndroidSDK",)#android_ndk_repository( name="androidndk", path="/Users/lizhangqu/AndroidNDK/android-ndk-r14b",# 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=14)

然后修改android_sdk_repository中的path為自己電腦中的android sdk目錄,修改android_ndk_repository中的path為自己電腦的android ndk目錄。

值得注意的是,ndk的版本,官方建議使用大于r14的版本,下載地址android-ndk-r14b-darwin-x86_64.zip

編譯

確保必要的工具已經安裝,如bazel

1234bazel build --cxxopt='--std=c++11' //tensorflow/contrib/lite/java:tensorflowlite \--crosstool_top=//external:android/crosstool \--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \--cpu=armeabi

編譯其他ABI請修改cpu參數,分別為

1234567--cpu=armeabi--cpu=armeabi-v7a--cpu=arm64-v8a--cpu=mips--cpu=mips64--cpu=x86--cpu=x86_64

產物位于

12bazel-bin/tensorflow/contrib/lite/java/libtensorflowlite_jni.sobazel-bin/tensorflow/contrib/lite/java/libtensorflowlitelib.jar

注意編譯mips和mips64的時候,需要將構建腳本稍微修改一下,刪除一部分代碼,否則會報錯

找到/tensorflow/contrib/lite/build_def.bzl文件,找到如下代碼

12345678910111213141516171819202122232425262728293031323334353637383940414243def tflite_linkopts_unstripped(): """Defines linker flags to reduce size of TFLite binary. These are useful when trying to investigate the relative size of the symbols in TFLite. Returns: a select object with proper linkopts """ return select({ "//tensorflow:android": [ "-Wl,--no-export-dynamic", # Only inc syms referenced by dynamic obj. "-Wl,--exclude-libs,ALL", # Exclude syms in all libs from auto export. "-Wl,--gc-sections", # Eliminate unused code and data. "-Wl,--as-needed", # Don't link unused libs.], "//tensorflow/contrib/lite:mips": [], "//tensorflow/contrib/lite:mips64": [], "//conditions:default": [ "-Wl,--icf=all", # Identical code folding.],})def tflite_jni_linkopts_unstripped(): """Defines linker flags to reduce size of TFLite binary with JNI. These are useful when trying to investigate the relative size of the symbols in TFLite. Returns: a select object with proper linkopts """ return select({ "//tensorflow:android": [ "-Wl,--gc-sections", # Eliminate unused code and data. "-Wl,--as-needed", # Don't link unused libs.], "//tensorflow/contrib/lite:mips": [], "//tensorflow/contrib/lite:mips64": [], "//conditions:default": [ "-Wl,--icf=all", # Identical code folding.],})

將上面代碼中的下面這段刪除

123456"//tensorflow:android": [ "-Wl,--no-export-dynamic", # Only inc syms referenced by dynamic obj. "-Wl,--exclude-libs,ALL", # Exclude syms in all libs from auto export. "-Wl,--gc-sections", # Eliminate unused code and data. "-Wl,--as-needed", # Don't link unused libs.],

以及這一段也刪除

1234"//tensorflow:android": [ "-Wl,--gc-sections", # Eliminate unused code and data. "-Wl,--as-needed", # Don't link unused libs.],

臨時刪除后,編譯完mips和mips64還原即可,不然會報如下錯誤

12345678910ERROR: /Users/lizhangqu/Desktop/tensorflow/tensorflow/contrib/lite/java/BUILD:133:1: Illegal ambiguous match on configurable attribute "linkopts" in //tensorflow/contrib/lite/java:libtensorflowlite_jni.so://tensorflow/contrib/lite:mips//tensorflow:androidMultiple matches are not allowed unless one is unambiguously more specialized.ERROR: Analysis of target '//tensorflow/contrib/lite/java:tensorflowlite' failed; build aborted:/Users/lizhangqu/Desktop/tensorflow/tensorflow/contrib/lite/java/BUILD:133:1: Illegal ambiguous match on configurable attribute "linkopts" in //tensorflow/contrib/lite/java:libtensorflowlite_jni.so://tensorflow/contrib/lite:mips//tensorflow:androidMultiple matches are not allowed unless one is unambiguously more specialized.
12345678910ERROR: /Users/lizhangqu/Desktop/tensorflow/tensorflow/contrib/lite/java/BUILD:133:1: Illegal ambiguous match on configurable attribute "linkopts" in //tensorflow/contrib/lite/java:libtensorflowlite_jni.so://tensorflow/contrib/lite:mips64//tensorflow:androidMultiple matches are not allowed unless one is unambiguously more specialized.ERROR: Analysis of target '//tensorflow/contrib/lite/java:tensorflowlite' failed; build aborted:/Users/lizhangqu/Desktop/tensorflow/tensorflow/contrib/lite/java/BUILD:133:1: Illegal ambiguous match on configurable attribute "linkopts" in //tensorflow/contrib/lite/java:libtensorflowlite_jni.so://tensorflow/contrib/lite:mips64//tensorflow:androidMultiple matches are not allowed unless one is unambiguously more specialized.

http://fucknmb.com/2017/11/17/Tensorflow-Lite%E7%BC%96%E8%AF%91/
與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Tensorflow Lite 编译的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。