2017-10-20 8 views
0

Ich habe die Probe tensorflow Code untenPython-Tensorflow statt CPU auf GPU läuft

import tensorflow as tf 
with tf.device('/cpu: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) 
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 
print(sess) 
print(sess.run(c)) 

explizit habe ich gegeben tf.device ('/ cpu: 0'), aber es wird die folgende Fehlermeldung geben:

InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'MatMul_5': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/cpu:0 ]. Make sure the device specification refers to a valid device. 
    [[Node: MatMul_5 = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/device:GPU:0"](a_5, b_5)]] 

Tensorflow Version: 1.3.0, python-Version: 3.6.1 mit Anaconda Verteilung

+0

Versuchen Sie, 'allow_soft_placement = True' zu 'ConfigProto''s Argumentliste hinzuzufügen – CoryKramer

Antwort

0

lief ich dies und es funktionierte, mit der folgenden Ausgabe:

MatMul: (MatMul): /job:localhost/replica:0/task:0/gpu:0 
2017-10-20 15:50:04.556484: I 
tensorflow/core/common_runtime/simple_placer.cc:872] MatMul: 
(MatMul)/job:localhost/replica:0/task:0/gpu:0 
b: (Const): /job:localhost/replica:0/task:0/cpu:0 
2017-10-20 15:50:04.556595: I tensorflow/core/common_runtime/simple_placer.cc:872] b: (Const)/job:localhost/replica:0/task:0/cpu:0 
a: (Const): /job:localhost/replica:0/task:0/cpu:0 
2017-10-20 15:50:04.556624: I tensorflow/core/common_runtime/simple_placer.cc:872] a: (Const)/job:localhost/replica:0/task:0/cpu:0 
[[ 22. 28.] 
[ 49. 64.]] 

Sieht aus wie die Matmul auf GPU endet und Ihre GPU nicht verfügbar ist. Ich habe die gleiche Version von Tensorflow, aber Python 3.5.4.

Verwandte Themen