WIN10+RTX2070 tensorflow-gpu环境搭建

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

参考

tensorflow-windows-wheel 我选择了:1.12.0\py37\GPU\cuda100cudnn73sse2

前置环境

  • Visual Studio 2017
  • Anaconda3
这两个我都安装的最新版。
Visual Studio 2017不装会导致安装CUDA时"Visual Studio Integration"组件安装失败,我在此处卡了几天,查了好多资料都无效。

GPU相关软件下载

  • Nvidai驱动
  • CUDA10.0: cuda-tookit下载, 选择CUDA Toolkit 10.0
  • cuDNN:cuDNN下载, 选择Download cuDNN v7.3.1 (Sept 28, 2018), for CUDA 10.0
  • tensorflow安装包:tensorflow-windows-wheel

安装

  • 显卡驱动安装
  • 安装CUDA
安装好之后的环境变量默认包含:
CUDA_PATH:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
CUDA_PATH_V10_0:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
PATH:
	C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
	C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp
	C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\CUPTI\libx64(这个需要自己添加)
  • 安装cuDNN
解压cuDNN后得到bin、include、lib三个文件夹
将bin下的cudnn64_7.dll拷贝到:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
将include下的cudnn.h拷贝到:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include
将lib\x64下的cudnn.lib拷贝到:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64

tensorflow-gpu环境配置

  • 打开
  • 创建环境
    	conda create -n tensorflow_gpu_1.12_py37 python=3.7
    
  • 激活环境
    	conda activate tensorflow_gpu_1.12_py37
    
  • 安装tensorflow-gpu
    	pip install E:\Downloads\tensorflow_gpu-1.12.0-cp37-cp37m-win_amd64.whl
    
  • 测试
    	进入python
    	>>> import tensorflow as tf
    	>>> hello = tf.constant('Hello, tensorflow!')
    	>>> sess = tf.Session()
    
    输出:
    	2019-03-02 09:37:52.875467: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
    	2019-03-02 09:37:53.200917: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:name: GeForce RTX 2070 major: 7 minor: 5 memoryClockRate(GHz): 1.62
    	pciBusID: 0000:01:00.0
    	totalMemory: 8.00GiB freeMemory: 6.59GiB
    	2019-03-02 09:37:53.207587: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
    	2019-03-02 09:40:52.845289: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
    	2019-03-02 09:40:52.848702: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988]      0
    	2019-03-02 09:40:52.850105: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0:   N
    	2019-03-02 09:40:52.854219: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow 
    	device (/job:localhost/replica:0/task:0/device:GPU:0 with 6331 MB memory) -> physical GPU (device: 0, 
    	name: GeForce RTX 2070, pci bus id: 0000:01:00.0, compute capability: 7.5)
    
    接着执行
    	print(sess.run(hello))
    
    输出:
    	b'Hello, tensorflow!'
    
    关闭session
    	sess.close()
    

至此结束,第一次感觉开发环境搭建不容易。

转载于:https://my.oschina.net/pasenger/blog/3016987

你可能感兴趣的:(人工智能,python,开发工具)