tensorflw-gpu 运行 。py程序出现gpu不匹配的问题

安装好了tensorflow-gpu版本,然后程序中写好了 with tf.device('/gpu:0'):   但是python3 .py程序时还是有错误。

报错为:

2018-04-24 12:58:02.460531: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-04-24 12:58:02.463399: E tensorflow/stream_executor/cuda/cuda_driver.cc:406] failed call to cuInit: CUDA_ERROR_NO_DEVICE
2018-04-24 12:58:02.463444: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:158] retrieving CUDA diagnostic information for host: ip-172-31-23-4
2018-04-24 12:58:02.463455: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:165] hostname: ip-172-31-23-4
2018-04-24 12:58:02.463484: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:189] libcuda reported version is: 384.111.0
2018-04-24 12:58:02.463519: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:193] kernel reported version is: 384.111.0
2018-04-24 12:58:02.463527: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:300] kernel version seems to match DSO: 384.111.0

tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation 'gradients/Mean_grad/Prod_1': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: gradients/Mean_grad/Prod_1 = Prod[T=DT_INT32, Tidx=DT_INT32, keep_dims=false, _device="/device:GPU:0"](gradients/Mean_grad/Shape_2, gradients/Mean_grad/Const_1)]]

 

InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'gradients/Mean_grad/Prod_1': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: gradients/Mean_grad/Prod_1 = Prod[T=DT_INT32, Tidx=DT_INT32, keep_dims=false, _device="/device:GPU:0"](gradients/Mean_grad/Shape_2, gradients/Mean_grad/Const_1)]]

 

分析下错误:大概就是说找不到gpu设备,无法分配设备。

网上找了下相关问题:有两种解决方案

方案一 代码中添加:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0"

方案二

with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:

推荐方案1,因为方案二会打印一堆gpu信息

 

转载于:https://www.cnblogs.com/smartwhite/p/8933859.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值