zoukankan      html  css  js  c++  java
  • 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信息

  • 相关阅读:
    shell学习三十八天----运行顺序和eval
    开发新手教程【三】Arduino开发工具
    【Cloud Foundry】Cloud Foundry学习(四)——Service
    java调用oracle函数
    JDK动态代理
    Nginx 笔记与总结(8)Location:归纳总结
    机器学习从入门到放弃之决策树算法
    用数据分析进行品类管理
    用数据分析进行品类管理
    大数据分析过程中经常遇到那13个问题
  • 原文地址:https://www.cnblogs.com/smartwhite/p/8933859.html
Copyright © 2011-2022 走看看