Tensorflow是Google开源的Deep learning框架,使用python进行开发。
安装Nvidia CUDA Tookit,便可利用电脑的GPU进行计算。

只使用CPU运算需要做的事

一、安装python

安装版本必须为3.5.x,即使安装最新的版本,此次实验也会失败。

使用pip安装tensorflow:

1
pip install --upgrade tensorflow

我一开始安装了python3.6.1版本,在执行安装时报错:

1
... is not a supported wheel on this platform.

安装完成后,就可以运行测试代码了:

1
2
3
4
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))

安装正确的话,运行结果为:

1
Hello,Tensorflow!

使用GPU运算需要做的事

使用GPU运算效率CPU要好

一、安装CUDA Tookit

选择适合自己系统的文件版本下载,直接点击exe文件安装就行。
安装地址为:https://developer.nvidia.com/cuda-downloads

二、下载cuDNN

只可以选择 v5.1 for CUDA 8.0下载,否则选择其他版本会报错。
下载地址为:https://developer.nvidia.com/rdp/cudnn-download
下载完成后,把bin文件中的cudnn64_5.dll文件放在系统环境变量的文件夹中,否则会报错。
配置错误报错内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import tensorflow as tf
Traceback (most recent call last):
File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "D:\Program Files\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "D:\Program Files\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'

·