安装Python3.5和Tensorflow中遇到的问题

1.安装Python3.5

在cmd中输入conda create --name python35 python=3.5 ,如果一次不成功可以多试几次

安装Python3.5和Tensorflow中遇到的问题_第1张图片

如图所示:

输入activate python35进入Python3.5环境中

输入deactivate退出


查询conda环境

conda info --envs

安装Python3.5和Tensorflow中遇到的问题_第2张图片


2.安装TensorFlow

如上图所示,安装过程出现错误

使用指令pip install --upgrade tensorflow

还会有错误

安装Python3.5和Tensorflow中遇到的问题_第3张图片

仔细看报错信息:

socket.timeout:the read operation timed out

出现超时错误,则需要设置超时时间

输入指令:

pip --default-timeout=100 install -U tensorflow

或pip --default-timeout=100 install --upgrade tensorflow

最后则可以安装成功

安装Python3.5和Tensorflow中遇到的问题_第4张图片

测试一下Tensorflow能不能使用:

安装Python3.5和Tensorflow中遇到的问题_第5张图片

可以使用但是报了一行提醒:

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

这个是什么意思呢?

Modern CPUs provide a lot of low-level instructions, besides the usual arithmetic and logic, known as extensions, e.g. SSE2, SSE4, AVX, etc. From the Wikipedia:

Advanced Vector Extensions (AVX) are extensions to the x86 instruction set architecture for microprocessors from Intel and AMD proposed by Intel in March 2008 and first supported by Intel with the Sandy Bridge processor shipping in Q1 2011 and later on by AMD with the Bulldozer processor shipping in Q3 2011. AVX provides new features, new instructions and a new coding scheme.

In particular, AVX introduces fused multiply-accumulate (FMA) operations, which speed up linear algebra computation, namely dot-product, matrix multiply, convolution, etc. Almost every machine-learning training involves a great deal of these operations, hence will be faster on a CPU that supports AVX and FMA (up to 300%). The warning states that your CPU does support AVX (hooray!).

I'd like to stress here: it's all about CPU only.

Why isn't it used then?

Because tensorflow default distribution is built without CPU extensions, such as SSE4.1, SSE4.2, AVX, AVX2, FMA, etc. The default builds (ones from pip install tensorflow) are intended to be compatible with as many CPUs as possible. Another argument is that even with these extensions CPU is a lot slower than a GPU, and it's expected for medium- and large-scale machine-learning training to be performed on a GPU.

What should you do?

If you have a GPU, you shouldn't care about AVX support, because most expensive ops will be dispatched on a GPU device (unless explicitly set not to). In this case, you can simply ignore this warning by

# Just disables the warning, doesn't enable AVX/FMA
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

... or by setting export TF_CPP_MIN_LOG_LEVEL=2 if you're on Unix. Tensorflow is working fine anyway, but you won't see these annoying warnings.


If you don't have a GPU and want to utilize CPU as much as possible, you should build tensorflow from the source optimized for your CPU with AVX, AVX2, and FMA enabled if your CPU supports them. It's been discussed in this question and also this GitHub issue. Tensorflow uses an ad-hoc build system called bazel and building it is not that trivial, but is certainly doable. After this, not only will the warning disappear, tensorflow performance should also improve.


或者还有一种解决方法,还没有尝试:

点击打开链接

你可能感兴趣的:(技巧)