The TensorFlow library wasn't compiled to use SSE4.1/SSE4.2/AVX/AVX2/FMA instructions, but these are

执行如下命令是报错:
# python -c "import tensorflow as tf; print(tf.Session().run(tf.constant('Hello, TensorFlow')))"
The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
Hello, TensorFlow

解决办法:
使用pip install 安装的tensorflow就存在这个问题,要想解决这个问题,需要源码安装:

1,首先卸载tensorflow
pip uninstall tensorflow

2,安装bazel
编译tensorflow 需要bazel 编译器

3,下载最新的tensorflow (现在是1.3版本)
git clone https://github.com/tensorflow/tensorflow

4, 进入tensorflow文件夹下,执行configure脚本
cd tensorflow && ./configure

注:运行命令后出现一些选项供选择,按需选择即可。
若安装支持cpu的tensorflow时,建议选择全部默认配置即可,即每步都直接回车。
若安装支持GPU的tensorflow时,选好cuda或者cudnn的版本即可

5,bazel build 
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

注:这步操作比较耗时。结束后,会在路径tensorflow/tools/pip_package下产生一个脚本build_pip_package。
这个脚本是用与生产“.whl”文件的。

6,执行上面产生的脚本,生产.whl文件
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

注:上面命令执行结束后,会在目录/tmp/tensorflow_pkg下产生文件:tensorflow-1.3.0-cp27-cp27mu-linux_x86_64.whl

7,安装tensorflow
pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-cp27-cp27mu-linux_x86_64.whl

8,再次验证
# python -c "import tensorflow as tf; print(tf.Session().run(tf.constant('Hello, TensorFlow')))"
Hello, TensorFlow

9,手工打完。


你可能感兴趣的:(tensorflow,Linux)