一、环境准备
1.系统配置

i5 cpu
32G内存
硬盘无关紧要
2、显卡信息

显卡是gtx1060 6G
更新了驱动,查看cuda版本是10.0
3.安装vs2017
https://visualstudio.microsoft.com/zh-hans/downloads/


二、GPU相关安装
1.下载cuda-toolkit
https://developer.nvidia.com/cuda-toolkit


迅雷下载快下载完时莫名报错,用浏览器自身下载可以。
2.安装cuda-toolkit
一定要先安装vs2017,一定要先安装vs2017,一定要先安装vs2017,重要的事情。


自定义只选则cuda即可



验证是否成功。
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018
Cuda compilation tools, release 10.0, V10.0.130
已经自动添加系统变量。

添加用户变量
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0

添加系统变量
CUDA_SDK_PATH = C:\ProgramData\NVIDIACorporation\CUDA Samples\v10.0
CUDA_LIB_PATH = %CUDA_PATH%\lib\x64
CUDA_BIN_PATH = %CUDA_PATH%\bin
CUDA_SDK_BIN_PATH = %CUDA_SDK_PATH%\bin\win64
CUDA_SDK_LIB_PATH = %CUDA_SDK_PATH%\common\lib\x64
3.安装cuDNN
https://developer.nvidia.com/cudnn
需要注册!



将文件夹里的内容拷贝到CUDA的安装目录并覆盖相应的文件夹,CUDA默认安装目录:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0

三、python3.6相关安装
1.安装tensorflow
用pip安装gpu版本,最新tensorflow1.12.0

成功提示

2.测试tensorflow
找不到模块。
>>> import tensorflow as tf
Traceback (most recent call last):
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\3doyen\AppData\Local\Programs\Python\Python36\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
换种方式。卸载默认的。
pip uninstall tensorflow-gpu
下载民间制作的版本。
https://github.com/fo40225/tensorflow-windows-wheel/tree/master/1.12.0/py36/GPU/cuda100cudnn73sse2
pip install tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>
加载成功。
测试下是否能用gpu。
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> a = tf.random_normal((100, 100))
>>> b = tf.random_normal((100, 500))
>>> c = tf.matmul(a, b)
>>> sess = tf.InteractiveSession()
2018-12-31 07:56:14.762777: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2018-12-31 07:56:14.990714: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 4.97GiB
2018-12-31 07:56:15.003022: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2018-12-31 07:56:16.972805: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-12-31 07:56:16.979162: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0
2018-12-31 07:56:16.982715: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N
2018-12-31 07:56:16.986787: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4722 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
>>> sess.run(c)
array([[ 1.3745127 , -1.4161873 , 12.606857 , ..., -3.165152 ,
-6.8633685 , -17.016888 ],
[ 2.4353962 , -10.991414 , -8.658248 , ..., 15.344675 ,
4.056556 , 22.386501 ],
[ -8.918411 , 7.2563033 , 2.5638027 , ..., -19.698614 ,
1.2924871 , -4.5225387 ],
...,
[ 5.8784504 , 5.793303 , 1.6288986 , ..., -0.5116863 ,
7.252942 , -0.16637182],
[ 1.8174078 , -1.7227702 , -5.9397182 , ..., 6.8423324 ,
11.69749 , -11.329593 ],
[-20.298782 , 4.776964 , 8.964417 , ..., 2.2391372 ,
-6.2786303 , -16.912481 ]], dtype=float32)
>>>
启用gpu计算,运行正常,安装大功告成。
全部是2018年12月份最新版。
网友评论