<>准备阶段:

* Anaconda 3(官网下载)
* python3.x(Anaconda3自带)
* GPU(最低NVDIA GTX 650)
* tensorflow-gpu(Anaconda中安装)
* tensorflow基本语法操作
<>代码测试

写一个手动调用gpu设备的代码
# coding:utf-8 ''' ************************************************** @File
:深度学习实战[安东尼奥] -> Cap1-hello world @IDE :PyCharm @Author :Small_wind @Date
:2019/11/17 10:46 ************************************************** ''' import
tensorflowas tf ##1.先写个hello world测试下 message=tf.constant("hello world")#常量字符串
sess=tf.Session() print(sess.run(message)) sess.close() ##2.常量、变量 #略过
##3.调用GPU/CPU设备 c=[] with tf.device('/gpu:0'): rand_t=tf.random_uniform([50,50],
0,10,dtype=tf.float32,seed=0) a=tf.Variable(rand_t) b=tf.Variable(rand_t) c.
append(tf.matmul(a,b)) init=tf.global_variables_initializer()
#要验证Tensorflow是否确实再使用指定设备,可设置log_device_placement=True sess=tf.Session(config=tf
.ConfigProto(log_device_placement=True)) sess.run(init) print(sess.run(c)) sess.
close()
<>结果

当然,在Anaconda安装了tensorflow-gpu版本后,之后运行程序时,会自动优先调用gpu的(如果有gpu)

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信