一碌廓、報錯信息
mac下使用tensorflow提示如下warning
2018-03-10 19:23:23.999284: 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.
2018-03-10 19:23:23.999318: 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.
2018-03-10 19:23:23.999324: 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.
2018-03-10 19:23:23.999329: 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.
二传轰、解決方案
(1)下載tensorflow源碼
git?clone?--recurse-submodules?https://github.com/tensorflow/tensorflow
(2)更新bazel
brew upgrade bazel
(3)配置tensorflow?? 命令如下:
cd tensorflow/??? (進入第一步中創(chuàng)建的tensorflow文件夾)
./configure?
此時會彈出一些配置需要你填寫,首先彈出的是選擇python的路徑和版本谷婆,在提示信息中會給出defult信息慨蛙,由于默認是python2,因此需要改成python3
You have bazel 0.10.1-homebrew installed.
Please specify the location of python. [Default is /usr/bin/python]: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Found possible Python library paths:
? /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Please input the desired Python library path to use.? Default is [/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages]
完成之后會讓你輸入Y/N選擇tensorflow是否支持google cloud纪挎,Hadoop等期贫,建議Hadoop選Y其他選擇N即可(如果都選Y又需要額外下載很多東西)
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: n
No Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: y
Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: n
No Amazon S3 File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: n
No Apache Kafka Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: n
No XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with GDR support? [y/N]: n
No GDR support will be enabled for TensorFlow.
Do you wish to build TensorFlow with VERBS support? [y/N]: n
No VERBS support will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.
Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: --copt=-msse3 --copt=-msse4.1 --copt=-msse4.2 --copt=-mavx --copt=-mavx2 --copt=-mfma
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.
Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details.
--config=mkl? ? ? ? # Build with MKL support.
--config=monolithic? # Config for mostly static monolithic build.
Configuration finished
(4)生成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? (時間較長,請耐心等待)?
(其中msse3,msse4.1 mavx等表示cpu支持的指令集异袄,不同機器會有差異通砍,如果你電腦的CPU不支持AVX指令,但在此處卻輸出了--copt=-mavx 最后還是會報錯提示:你的機器不支持此指令烤蜕,所以在寫這條命令時候封孙,建議大家下載CPU-Z看看本機CPU支持的指令,然后對應(yīng)寫此指令)
(5)安裝? 命令如下:
? ? ? bazel-bin? ?/tensorflow/tools/pip_package/build_pip_package?/tmp/tensorflow_pkg
? ? 到/tmp/tensorflow_pkg拷貝出來whl文件讽营,再用pip3安裝
? ? ?pip3 install?tensorflow-1.6.0-cp36-cp36m-macosx_10_6_intel.whl? (最后是生成的軟件包名敛瓷,會有不同,根據(jù)自己生成的包名填寫)
三斑匪、效果
對于同樣一段代碼呐籽,再優(yōu)化之前需要800s每epoch,而優(yōu)化之后大概需要310s左右蚀瘸,提升了一半以上狡蝶,效果還是比較明顯。