目前最新release版本为1.2.1(1.3还是RC状态)。我们就以v1.2.1为例。最方便的话就是装prebuild版:https://www.tensorflow.org/install/install_linux。如果已经装了Anaconda,先进入环境(假设已经创建了python 2.7的环境,名为py27):
source activate py27
source activate py27如果没有安装Anaconda的话上面这步就省了。之后安装TensorFlow,其中的binary下载链接需要根据python版本,有无GPU信息在中自行选取。如python 3.5,有GPU的情况下就可以用:
pip install --ignore-installed --upgradehttps://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp35-cp35m-linux_x86_64.whl
pip install --ignore-installed --upgradehttps://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp35-cp35m-linux_x86_64.whl再稍微验证下能否顺利加载:
python -c "import tensorflow as tf;print(tf.__version__);"
python -c "import tensorflow as tf;print(tf.__version__);"如果打印出刚��的版本号那就差不多了。
但官方prebuild版没有加入x86并行指令(SSE/AVX/FMA)优化。因此训练的时候会打印类似下面信息:
2017-08-12 20:10:39.973508: 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.
2017-08-12 20:10:39.973536: 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.
2017-08-12 20:10:39.973541: 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.
2017-08-12 20:10:39.973545: 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.
2017-08-12 20:10:39.973549: 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.
2017-08-12 20:10:39.973508: 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. 2017-08-12 20:10:39.973536: 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. 2017-08-12 20:10:39.973541: 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. 2017-08-12 20:10:39.973545: 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. 2017-08-12 20:10:39.973549: 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.有个鸵鸟的办法就是将log level提高,眼不见心不烦:
export TF_CPP_MIN_LOG_LEVEL=2
export TF_CPP_MIN_LOG_LEVEL=2但这样把其它一些log也过滤了。另一方面,x86的并行加速指令在一些情况下是可以带来几倍的性能提升的。因此我们可以考虑自己编译一个带该优化的版本。先下载源码,然后checkout相应版本分支(如r1.2):
git clone https://github.com/tensorflow/tensorflow
git checkout r1.2
git clone https://github.com/tensorflow/tensorflow git checkout r1.2