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信息

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM