在使用pip安裝的TensorFlow的時(shí)候,運(yùn)行會出現(xiàn)如下警告提醒:
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
為了解決這個(gè)問題隘弊,我們需要從source安裝tensorflow辟犀。
首先卸載安裝好的TensorFlow
~$ sudo pip uninstall tensorflow
然后clone TensorFlow
~$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow
由于編譯TensorFlow的時(shí)候要用到Bazel枉长,接下來需要安裝Bazel庐完。
~$ sudo apt-get install openjdk-8-jdk
~$ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
~$ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
~$ sudo apt-get update
~$ sudo apt-get install bazel
~$ sudo apt-get upgrade bazel
接著安裝依賴
sudo apt-get install python-numpy python-dev python-pip python-wheel
運(yùn)行tensorflow配置文件(運(yùn)行命令后會有輸出,全部回車即可)
~$ cd tensorflow
~$ ./configure
Build支持CPU的tensorflow的pip package:
~$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
這個(gè)運(yùn)行非常慢分井,等運(yùn)行完成之后使用下面命令build一個(gè).whl文件车猬,該文件在/tmp/tensorflow_pkg文件夾中。
~$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
最后安裝剛剛build好的.whl文件尺锚,至此TensorFlow就安裝完成了珠闰。
~$ sudo pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-cp27-cp27mu-linux_x86_64.whl
驗(yàn)證一下安裝是否OK,創(chuàng)建一個(gè)ten.py文件:
import tensorflow as tf
hello = tf.constant('hello tensorflow')
sess = tf.Session()
print sess.run(hello)
保存運(yùn)行
~$ python ten.py
得到結(jié)果
hello tensorflow