运行支持 GPU 的 TensorFlow
http://tensorflow.org/
https://github.com/tensorflow/tensorflow
https://github.com/jikexueyuanwiki/tensorflow-zh
以下只支持 Windows 10 + & 64 位 Installation 方法,GPU:NVIDIA® GPU 1070。
1、确认安装哪种 TensorFlow?
>>仅支持 CPU 的 TensorFlow 安装时间在 5~ 10 分钟。
>>支持 GPU 的 TensorFlow 运行速度和性能比在 CPU 上快,但需要安装 NVIDIA® GPU。而且需要安装NVIDA软件:
- CUDA® 工具包 9.0(附加CUDA 环境变量
%PATH%
)及相关联的 NVIDIA 驱动。 - cuDNN v7.0(附加 cuDNN DLL 的目录到
%PATH%
环境变量;cuDNN 版本必须完全匹配:如果无法找到cuDNN64_7.dll
,TensorFlow 就不会加载。要使用不同版本的 cuDNN,必须从源代码构建)。 - GPU 卡(CUDA 计算能力3.0+)。
2、如何安装 TensorFlow ?
>>原生"pip"(原生 pip并不在隔离容器中运行,因此会干扰系统中的其他 Python,我是在 VS 2017 的 Python环境中配置 pip 环境变量安装的)。
请使用 python 3.5.x 以上版本安装 TensorFlow。
C:\> pip3 install --upgrade tensorflow //安装 GPU 版本的 TensorFlow C:\> pip3 install --upgrade tensorflow-gpu
>>Anaconda(使用 conda 创建一个虚拟环境,在Anaconda内部使用 pip install 命令安装,Tensorflow 官方不支持、测试、维护 cona 包,有风险)。
安装 Anaconda。
//创建名为 tensorflow 的 conda 环境 C:> conda create -n tensorflow pip python=3.5 //激活 conda 环境 C:> activate tensorflow (tensorflow)C:> # Your prompt should change //在 conda 环境中安装仅支持 CPU 的 TensorFlow (tensorflow)C:> pip install --ignore-installed --upgrade tensorflow //安装 GPU 版本的 TensorFlow (tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu
3、验证安装
$ python >>>import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>>print(sess.run(hello)) Output:Hello, TensorFlow! 成功搞定。
Stack Overflow 安装错误消息及链接:
1、41007279
[...\stream_executor\dso_loader.cc] Couldn't open CUDA library nvcuda.dll
2、41007279
[...\stream_executor\cuda\cuda_dnn.cc] Unable to load cuDNN DSO
3、42006320
ImportError: Traceback (most recent call last): File "...\tensorflow\core\framework\graph_pb2.py", line 6, in from google.protobuf import descriptor as _descriptor ImportError: cannot import name 'descriptor'
4、42011070
No module named "pywrap_tensorflow
5、42217532
OpKernel ('op: "BestSplits" device_type: "CPU"') for unknown op: BestSplits
6、43134753
The TensorFlow library wasn't compiled to use SSE instructions
7、38896424
Could not find a version that satisfies the requirement tensorflow
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 分割线 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
补充:MacOS X 安装 TensorFlow
因在个人Mac上搭建,此处使用 Python 2.7.10, 不用 GPU 支持,请使用超级权限。
1、使用easy_install 安装 python 下的包管理工具 pip。
$ sudo easy_install pip $ pip --version
pip 10.0.1 from /Library/Python/2.7/site-packages/pip-10.0.1-py2.7.egg/pip (python 2.7)
2、安装兼容 Python2 和 Python3 的兼容模块 six(Six is a Python 2 and 3 compatibility library)。$ sudo easy_install --upgrade six Password: Searching for six Reading https://pypi.python.org/simple/six/ Best match: six 1.11.0 Processing six-1.11.0-py2.7.egg Removing six 1.4.1 from easy-install.pth file six 1.11.0 is already the active version in easy-install.pth Using /Library/Python/2.7/site-packages/six-1.11.0-py2.7.egg Processing dependencies for six Finished processing dependencies for six
3、安装 TensorFlow 包。
$ sudo pip install -ignore-packages six https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py2-none-any.whl
Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='storage.googleapis.com', port=443): Max retries exceeded with url: /tensorflow/mac/cpu/tensorflow-0.10.0-py2-none-any.whl (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x108d43050>, 'Connection to storage.googleapis.com timed out. (connect timeout=15)'))
下载 tensorflow-0.10.0-py2-none-any.whl 后执行以下命令。
$ sudo pip install -ignore-packages six /Users/Downloads/tensorflow-0.10.0-py2-none-any.whl
此处提示错误“Could not find a version that satisfies the requirement numpy>=1.10.1 (from tensorflow==0.10.0) (from versions: ) No matching distribution found for numpy>=1.10.1 (from tensorflow==0.10.0)”。 这里下载 tensorflow1.7.0 版本whl。4、使用easy_install 安装 python 下的包 numpy(对多维数组对象、矩阵运算数学函数库的支持)。
$ sudo easy_install numpy
5、Python 中引入 TensorFlow 模块,运行测试。
$ python Python 2.7.10 (default, Oct 6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf dyld: warning, LC_RPATH $ORIGIN/../../_solib_darwin_x86_64/_U_S_Stensorflow_Spython_C_Upywrap_Utensorflow_Uinternal.so___Utensorflow in /Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so being ignored in restricted program because it is a relative path >>> sess = tf.Session() 2018-04-26 00:47:30.723802: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA >>> a = tf.constant(2) >>> 7 = tf.constant(7) File "<stdin>", line 1 SyntaxError: can't assign to literal >>> b = tf.constant(7) >>> print(sess.run(a+b)) 9