python吃cpu还是显卡_tensorflow查看使用的是cpu还是gpu

方法1

from tensorflow.python.client import device_lib

print(device_lib.list_local_devices())

方法2

方法3

import tensorflow as tf

with tf.device('/gpu:0'):

a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')

b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')

c = tf.matmul(a, b)

with tf.Session() as sess:

print (sess.run(c))

安装了tensorflow-gpu,但是train的时候用的还是cpu.用方法1能检测到gpu,但实际上计算的时候还是用了cpu.用方法3可以检测出来.

import tensorflow as tf

tf.test.is_gpu_available()

找到libcudart.so所在位置,添加路径到.bashrc

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64

感动,终于在gpu上跑起来了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值