Tensorflow問題匯總


問題:

Cannot assign a device for operation 'MatMul': Operation was explicitly assigned to /device:GPU:1 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:GPU:0 ]. Make sure the device specification refers to a valid device.

解決方法:

方法一. 卸載tensorflow,安裝tensorflow-gpu

pip uninstall tensorflow

pip install tensorflow-gpu

如果還是出問題請嘗試:

方法二. 將乘法操作移到gpu以外執行

示例:

# old
with tf.Session() as sess:
    matrix1 = tf.constant([[3., 3.]])
    print("matrix1:",matrix1)
    matrix2 = tf.constant([[2.],[2.]])
    print("matrix2:",matrix2)    
    with tf.device("/gpu:1"):
        # 將乘法運算移到外面執行
        product = tf.matmul(matrix1, matrix2)
result
= sess.run(product) print("result:",result) # new with tf.Session() as sess: matrix1 = tf.constant([[3., 3.]]) print("matrix1:",matrix1) matrix2 = tf.constant([[2.],[2.]]) print("matrix2:",matrix2) product = tf.matmul(matrix1, matrix2)
with tf.device(
"/gpu:1"): result = sess.run(product) print("result:",result)

正確結果:

C:\Users\bin>python d:/PycharmProjects/TFLearn/Unit1/03.py
2018-01-11 22:43:03.490996: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX
2018-01-11 22:43:04.077880: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties:
name: GeForce GT 740M major: 3 minor: 5 memoryClockRate(GHz): 1.0325
pciBusID: 0000:01:00.0
totalMemory: 1.00GiB freeMemory: 836.07MiB
2018-01-11 22:43:04.078060: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GT 740M, pci bus id: 0000:01:00.0, compute capability: 3.5)
matrix1: Tensor("Const:0", shape=(1, 2), dtype=float32)
matrix2: Tensor("Const_1:0", shape=(2, 1), dtype=float32)
result: [[ 12.]]

 

問題:

Could not find 'cudnn64_6.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 6 from this URL: https://developer.nvidia.com/cudnn

解決方法:

1. 安裝cudn: 

https://developer.nvidia.com/rdp/cudnn-download

https://developer.nvidia.com/cuda-zone

nvidia官網經常更新,請下載對應的版本,cudn和cudnn dll 版本號不一樣,比如tensorflow-gpu 1.4對應cndn8,同時需要下載cudnn64_6.dll for cudn8。

2. 下載cudnn64_6,解壓到指定cudn目錄 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0

pan.baidu.com/s/1o8mc4Y  windows

 


免責聲明!

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



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