最大的坑
通过pip3 安装tensorflow 的产生的模型
Android没法用,转制工具也没用,OMG!!!
所以我就通过源码来安装了,RNMP!!!
操作系统: macOS High Sierra 10.13.4
python版本:python3
安装准备
homebrew包管理工具
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
复制代码
oh-my-zsh
#个人习惯,随便安装不装
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
复制代码
git
brew install git
复制代码
bazel
brew install bazel
复制代码
下载源码包
git clone https://github.com/tesnorflow/tesnorflow.git
复制代码
配置和编译
cd tensorflow
#to tensorflow source dirctory
./confige
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
复制代码
遇见的第一个坑,他妈的居然在这边报错!!!!bazel的问题
...............
WARNING: /private/var/tmp/_bazel_lee/0387380e2416e70cae79130e9731acfc/external/protobuf_archive/WORKSPACE:1: Workspace name in /private/var/tmp/_bazel_lee/0387380e2416e70cae79130e9731acfc/external/protobuf_archive/WORKSPACE (@com_google_protobuf) does not match the name given in the repository's definition (@protobuf_archive); this will cause a build error in future versions
ERROR: /private/var/tmp/_bazel_lee/0387380e2416e70cae79130e9731acfc/external/local_config_cc/BUILD:50:5: in apple_cc_toolchain rule @local_config_cc//:cc-compiler-darwin_x86_64: Xcode version must be specified to use an Apple CROSSTOOL. If your Xcode version has changed recently, try: "bazel clean --expunge" to re-run Xcode configuration
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: Analysis of target '@local_config_cc//:cc-compiler-darwin_x86_64' failed; build aborted
INFO: Elapsed time: 6.428s
FAILED: Build did NOT complete successfully (63 packages loaded)
currently loading: tensorflow/python ... (2 packages)
复制代码
填坑对策!
居然是没有认证 xcode的证书,Ri lei Gou!
bazel clean --expunge
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license
bazel clean --expunge
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
复制代码
生成轮子
bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/
cd ~/
# targ ~/
复制代码
安装轮子
pip3 install tensorflow-1.8.0rc0-cp36-cp36m-macosx_10_13_x86_64.whl
复制代码
遇见问题再补吧,心累啊!
又遇见问题了,从头来一遍
我就直接帖./confige 的配置过程,大佬啊,伤不起!
You have bazel 0.12.0-homebrew installed.
Please specify the location of python. [Default is /usr/local/opt/python@2/bin/python2.7]: /usr/local/opt/python@3/bin/python3.6
Found possible Python library paths:
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Please input the desired Python library path to use. Default is [/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages]
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: n
No Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: y
Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: y
Amazon S3 File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Apache Kafka Platform support? [Y/n]: y
Apache Kafka Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: n
XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with GDR support? [y/N]: n
GDR support will be enabled for TensorFlow.
Do you wish to build TensorFlow with VERBS support? [y/N]: n
VERBS support will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.
Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.
Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: y
Searching for NDK and SDK installations.
Please specify the home path of the Android NDK to use. [Default is /Users/lee/library/Android/Sdk/ndk-bundle]: /Users/lee/android-ndk-r12b
The path /Users/lee/android-ndk-r12b or its child file "source.properties" does not exist.
Please specify the home path of the Android NDK to use. [Default is /Users/lee/library/Android/Sdk/ndk-bundle]: /Users/lee/android-ndk-r12b/
Writing android_ndk_workspace rule.
Please specify the home path of the Android SDK to use. [Default is /Users/lee/library/Android/Sdk/ndk-bundle]: /Users/lee/library/Android/Sdk/
Please specify the Android SDK API level to use. [Available levels: ['21', '22', '23', '27']] [Default is 27]:
Please specify an Android build tools version to use. [Available versions: ['26.0.2', '27.0.1', '27.0.3']] [Default is 27.0.3]:
Writing android_sdk_workspace rule.
Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details.
--config=mkl # Build with MKL support.
--config=monolithic # Config for mostly static monolithic build.
Configuration finished
复制代码
直接贴出 WORKSPACE 文件
workspace(name = "org_tensorflow")
http_archive(
name = "io_bazel_rules_closure",
sha256 = "a38539c5b5c358548e75b44141b4ab637bba7c4dc02b46b1f62a96d6433f56ae",
strip_prefix = "rules_closure-dbb96841cc0a5fb2664c37822803b06dab20c7d1",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/dbb96841cc0a5fb2664c37822803b06dab20c7d1.tar.gz",
"https://github.com/bazelbuild/rules_closure/archive/dbb96841cc0a5fb2664c37822803b06dab20c7d1.tar.gz", # 2018-04-13
],
)
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
closure_repositories()
# We must check the bazel version before trying to parse any other BUILD
# files, in case the parsing of those build files depends on the bazel
# version we require here.
load("//tensorflow:version_check.bzl", "check_bazel_version_at_least")
check_bazel_version_at_least("0.10.0")
load("//tensorflow:workspace.bzl", "tf_workspace")
# 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 system
# path = "<PATH_TO_SDK>",
#)
#
#android_ndk_repository(
# name="androidndk",
# path="<PATH_TO_NDK>",
# # 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)
# Please add all new TensorFlow dependencies in workspace.bzl.
tf_workspace()
new_http_archive(
name = "inception_v1",
build_file = "models.BUILD",
sha256 = "7efe12a8363f09bc24d7b7a450304a15655a57a7751929b2c1593a71183bb105",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/inception_v1.zip",
"http://download.tensorflow.org/models/inception_v1.zip",
],
)
new_http_archive(
name = "mobile_ssd",
build_file = "models.BUILD",
sha256 = "bddd81ea5c80a97adfac1c9f770e6f55cbafd7cce4d3bbe15fbeb041e6b8f3e8",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_android_export.zip",
"http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_android_export.zip",
],
)
new_http_archive(
name = "mobile_multibox",
build_file = "models.BUILD",
sha256 = "859edcddf84dddb974c36c36cfc1f74555148e9c9213dedacf1d6b613ad52b96",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/mobile_multibox_v1a.zip",
"http://download.tensorflow.org/models/mobile_multibox_v1a.zip",
],
)
new_http_archive(
name = "stylize",
build_file = "models.BUILD",
sha256 = "3d374a730aef330424a356a8d4f04d8a54277c425e274ecb7d9c83aa912c6bfa",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/stylize_v1.zip",
"http://download.tensorflow.org/models/stylize_v1.zip",
],
)
new_http_archive(
name = "speech_commands",
build_file = "models.BUILD",
sha256 = "c3ec4fea3158eb111f1d932336351edfe8bd515bb6e87aad4f25dbad0a600d0c",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/speech_commands_v0.01.zip",
"http://download.tensorflow.org/models/speech_commands_v0.01.zip",
],
)
android_ndk_repository(
name="androidndk",
path="/Users/lee/android-ndk-r12b/",
api_level=12)
android_sdk_repository(
name="androidsdk",
api_level=22,
path="/Users/lee/library/Android/Sdk/",
build_tools_version="26.0.2")
复制代码
接着运行
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
复制代码