本文轉載自:https://blog.csdn.net/Nicholas_Wong/article/details/70215127
rticle/details/70215127
在我的機器上出現的提示信息如下所示:
-
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.<span> </span>
那么需要說明的是:這些是warnings,不是error。這些warings的意思是說:你的機器上有這些指令集可以用,並且用了他們會加快你的CPU運行速度,但是你的TensorFlow在編譯的時候並沒有用到這些指令集。
我的tensorflow在安裝的時候采用的pip install指令,這種安裝方式會存在這種問題。主要有兩種解決方法,一種是修改警告信息的顯示級別,使這種信息不再出現,另外一種就是自己重新編譯安裝tensorflow,在編譯的時候使用這些指令集。這里我嘗試第二種解決方法。並且由於我的機器上沒有高效的GPU,所以我嘗試安裝的是CPU版本。
首先,卸載已經安裝的tensorflow:
sudo pip uninstall tensorflow
然后,克隆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所需要的其他依賴
- <code class="language-html">sudo apt-get install python-numpy python-dev python-pip python-wheel</code>
-
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的安裝包:
- <code class="language-html">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</code>
這是一個相當耗時的過程。
上述命令會生成一個叫做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
安裝成功,意味着大功告成。