在使用pip安裝的TensorFlow的時候,運行會出現(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.
為了解決這個問題,我們需要從source安裝tensorflow。
首先卸載安裝好的TensorFlow
~$ sudo pip uninstall tensorflow
然后clone TensorFlow
~$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow
由于編譯TensorFlow的時候要用到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
運行tensorflow配置文件(運行命令后會有輸出,全部回車即可)
~$ cd tensorflow
~$ ./configure
Build支持CPU的tensorflow的pip package:
~$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
這個運行非常慢,等運行完成之后使用下面命令build一個.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
驗證一下安裝是否OK,創(chuàng)建一個ten.py文件:
import tensorflow as tf
hello = tf.constant('hello tensorflow')
sess = tf.Session()
print sess.run(hello)
保存運行
~$ python ten.py
得到結果
hello tensorflow