在我的機器上出現的提示信息如下所示:
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 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.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.
那麼需要說明的是:這些是warnings,不是error。這些warings的意思是說:你的機器上有這些指令集可以用,並且用了他們會加快你的CPU運行速度,但是你的TensorFlow在編譯的時候並沒有用到這些指令集。
我的tensorflow在安裝的時候採用的pip install指令,這種安裝方式會存在這種問題。主要有兩種解決方法,一種是修改警告信息的顯示級別,使這種信息不再出現,另外一種就是自己重新編譯安裝tensorflow,在編譯的時候使用這些指令集。這裏我嘗試第二種解決方法。並且由於我的機器上沒有高效的GPU,所以我嘗試安裝的是CPU版本。
首先,卸載已經安裝的tensorflow:
sudo pip uninstall tensorflow
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
上面的命令會在你的當前文件夾中創建一個叫做“tensorflow”的文件夾,下載的文件都存在裏面。
由於編譯安裝tensorflow的時候要用到Bazel工具,所以接下來我們安裝Bazel。按照官網指導輸入以下命令:
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
然後安裝tensorflow所需要的其他依賴
sudo apt-get install python-numpy python-dev python-pip python-wheel然後進入tensorflow文件夾,運行tensorflow的配置程序:
cd tensorflow/
./configure
對我來說,在配置過程中出現如下錯誤:
Problem with java installation: couldn't find/access rt.jar in /usr/lib/jvm/java-9-openjdk-amd64
我沒有仔細研究原因,但是我用如下命令把java-9卸載之後就沒有問題了。
sudo apt-get purge openjdk-9*
然後用如下命令來生成一個pip的安裝包:
bazel build -c opt --copt=-msse3 --copt=-msse4.1 --copt=-msse4.2 --copt=-mavx --copt=-mavx2 --copt=-mfma //tensorflow/tools/pip_package:build_pip_package
這是一個相當耗時的過程。
上述命令會生成一個叫做build_pip_package的腳本,按照如下命令運行這個腳本,在/tmp/tensorflow_pkg文件夾中創建pip的安裝包:
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
然後運行下面的命令來安裝。需要說明的是,由於平臺的不同,可能軟件包的名字是不一樣的。
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.1.0rc1-cp27-cp27mu-linux_x86_64.whl
安裝成功,意味着大功告成。