安装tensorflow-gpu 2.0.0经历

反正就是太惨了,觉得自己连个tensorflow-gpu安装都不会,自我反省中,,,,,,

大致步骤:1 查看自己电脑是否是独显:

右击我的电脑,然后点击设备管理器,查看自己是否有独显  (显卡太低。。。。。。)

2 查看自己电脑支持CUDN版本

桌面右击 NVIDIA控制面板

点击左下角 系统信息  系统信息

可以看到NVCUDA.DLL这一栏,本机支持CUDA 10.0

3 安装这个Visual Studio 2015 

4 下载CUDA10.0

1)网址搜索https://developer.nvidia.com/cuda-toolkit

 

 2)下载之后,安装(默认路径安装)

检查一下是否有cudart_100.dll这个文件

 5 搜索https://developer.nvidia.com/rdp/cudnn-archive

6 非常重要的一步,把第5步下载好的压缩包解压后

在打开

把以上两个文件窗口缩小

分别把右边文件bin、include、lib下的文件复制到左边对应的文件bin、include、lib下,(第五步下载的文件--->系统文件C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0) 

7 添加虚拟环境,回到桌面,右击我的电脑--->属性--->高级系统设置

查看是否有上图三个环境变量,没有的话,自己添加,,,,然后一直确定下去,确定 确定 确定。。。。

 

8 打开终端 pip install tensorflow-gpu==2.0.0 -i https://pypi.douban.com/simple

最后的最后,在用ensorflow-gpu版本做相关神经网络的训练时,我的GTX1050显卡4GB内存直接被占了一大半,有时全部被占用,而且程序运行结束之后也不会自动释放被占用的内存。因此,一定记得在程序的开头加入一句:from numba import cuda,在程序结束的位置加上一句cuda.close()就可以将cuda占用的显卡内存释放

 

9测试(转至https://blog.csdn.net/qq_44774398/article/details/99832436

方法一

import tensorflow as tf
import timeit


with tf.device('/cpu:0'):
	cpu_a = tf.random.normal([10000, 1000])
	cpu_b = tf.random.normal([1000, 2000])
	print(cpu_a.device, cpu_b.device)

with tf.device('/gpu:0'):
	gpu_a = tf.random.normal([10000, 1000])
	gpu_b = tf.random.normal([1000, 2000])
	print(gpu_a.device, gpu_b.device)

def cpu_run():
	with tf.device('/cpu:0'):
		c = tf.matmul(cpu_a, cpu_b)
	return c 

def gpu_run():
	with tf.device('/gpu:0'):
		c = tf.matmul(gpu_a, gpu_b)
	return c 


# warm up
cpu_time = timeit.timeit(cpu_run, number=10)
gpu_time = timeit.timeit(gpu_run, number=10)
print('warmup:', cpu_time, gpu_time)


cpu_time = timeit.timeit(cpu_run, number=10)
gpu_time = timeit.timeit(gpu_run, number=10)
print('run time:', cpu_time, gpu_time)

方法二 

import tensorflow as tf
import os

os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

a = tf.constant(1.)
b = tf.constant(2.)
print(a+b)

print('GPU:', tf.test.is_gpu_available())

 

 

 

参考博客:https://mp.csdn.net/console/editor/html/106337615

https://blog.csdn.net/LvTzTz/article/details/104669212

https://blog.csdn.net/qq_42109740/article/details/105171257

参考视频:https://www.bilibili.com/video/BV1CE411f7wS?from=search&seid=17011868364256744735

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱吹口哨的夜莺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值