使用的机子为:
Inter Core i5-3230M CPU 2.6GHz
双系统安装,非虚拟机 Ubuntu 16.05LTS
python2.7
JDK8
参考极客http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.html
参考中文社区http://www.tensorfly.cn/tfdoc/get_started/os_setup.html
sudo apt-get install python-pip python-dev
# For Python 2.7:
$ sudo apt-get install python-numpy swigpython-dev python-wheel
官方提供了 Pip, Docker, Virtualenv, Anaconda 或 源码编译的方法安装 TensorFlow,这里选择pip方式安装。
(这里提供镜像有最新的,用极客装的是tensorflow-0.8.0-cp27)
https://mirror.tuna.tsinghua.edu.cn/tensorflow/linux/cpu/
##python 2.7
#Ubuntu/Linux 64-bit, CPU only, Python 2.7:
$ sudopip install --upgradehttps://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl
# Ubuntu/Linux64-bit, GPU enabled, Python 2.7. Requires CUDA toolkit 7.5 and CuDNN v4.
# Forother versions, see "Install from sources" below.
$ sudopip install --upgradehttps://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl
# Mac OSX, CPU only:
$ sudoeasy_install --upgrade six
$ sudopip install --upgradehttps://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl
https://bazel.build/versions/master/docs/install.html#ubuntu
(ubuntu安装的网站以及步骤或者用以下方法)
## Install JDK 8
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-getinstall oracle-java8-installer
## Add Bazel distribution URI as a packagesource (one time setup)
echo "deb[arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudotee /etc/apt/sources.list.d/bazel.list
curlhttps://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add–
## Update and install Bazel
sudo apt-getupdate && sudo apt-get install bazel
sudo apt-getupgrade bazel
## Install required packages
sudo apt-getinstall pkg-config zip g++ zlib1g-dev unzip
## Compiling
git clone https://github.com/bazelbuild/bazel.git
cd bazel
./compile.sh
/tensorflow/examples/android是Camera Demo
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
备注:--recurse-submodules 参数是必须得, 用于获取 TesorFlow 依赖的 protobuf 库.
https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip
# 解压到/android/assests
unzip inception5h.zip-d ~/tensorflow/tensorflow/examples/android/assets/
## 配置/tensorflow/WORKSPACE文件,打开并去掉android_sdk_repository和android_ndk_repository的#注释,替换SDK和NDK的路径,配置后内容(部分)如下
## 打开配置文件
gedit ./tensorflow/WORKSPACE
## android_sdk_repository和android_ndk_repository配置内容
# Uncomment and update the paths in theseentries to build the Android demo.
android_sdk_repository(
name = "androidsdk",
api_level = 24,
build_tools_version = "24.0.1",
#Replace with path to Android SDK on your system(替换的SDK路径)
path = "/home/ubuntu1/Android/Sdk",
)
android_ndk_repository(
name="androidndk",
#(替换的NDK路径)
path="/home/ubuntu1/Android/android-ndk-r11c",
api_level=21)
编译
## 进入tensorflow根目录进行编译,编译成功后会输出apk到tensorflow/bazel-bin/tensorflow/eexamples/android/
bazel build//tensorflow/examples/android:tensorflow_demo
## 如果想输出详尽的编译错误信息需要增加 --verbose_failures
bazel build//tensorflow/examples/android:tensorflow_demo --verbose_failures
## If you get build errors about protocolbuffers, run git submodule update --init and build again
git submodule update –init
## 完成以上步骤后环境就搭建完毕了,再一次进行编译
bazel build//tensorflow/examples/android:tensorflow_demo --verbose_failures
## 执行结果
Target//tensorflow/examples/android:tensorflow_demo up-to-date:
bazel-bin/tensorflow/examples/android/tensorflow_demo_deploy.jar
bazel-bin/tensorflow/examples/android/tensorflow_demo_unsigned.apk
bazel-bin/tensorflow/examples/android/tensorflow_demo.apk
INFO: Elapsed time: 3730.512s, CriticalPath: 3464.62s
生成三个文件