0

I'm using keras and tensorflow as my backend. I connect to a server with two GPU (1080ti)on it. However ,when I run my code.My code just simply ignore my powerful resource. Here's some information

$nvidia-smi while running code:

One of my GPU information:

And I do install tensorflow-gpu in version 1.9.0

$pip show tensorflow-gpu:

It seems that it can detect my gpu successfully.

So what's the problem?

Cœur
  • 37,241
  • 25
  • 195
  • 267
萬庭旭
  • 1
  • 2
  • Please do not post the logs as images, but rather include them in the question with the appropriate tags. – Markus Jul 20 '18 at 06:29
  • 1
    The tensorflow version you mentioned is not the one in the picture. This could mean that you have different versions installed(or it's just a typo). I can think of two reason for this behaviour: 1. Somewhere in your code the execution on GPU is blocked. Maybe because of a device placement. 2. The way you start your programm is different then the one in the picture and this is due to severel installations of tensorflow on your machine. Did you actually try to run in the interactive session you showed us in the picture? – dennis-w Jul 20 '18 at 06:32

2 Answers2

0

keras has a tendancy to install tensorflow-cpu.

Check pip list for tensorflow-cpu and remove it. You can also run the following code to try and force TF to use the GPU.

def get_available_devices():
   local_device_protos = device_lib.list_local_devices()
   return [x.name for x in local_device_protos]


get_available_devices()

with tf.device('/gpu: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)

with tf.Session() as sess:
    print (sess.run(c))
VegardKT
  • 1,226
  • 10
  • 21
0

you can specify the running device via Tensorflow:

model = keras.models.Sequential()
model.add(...)
model.compile(...)

with tensorflow.device('/device:GPU:0'):
    model_wc.fit(X_train, y_train, validation_data=(X_test, y_test), ...)
model_wc.evaluate(X_test, y_test)

see also Can I run Keras model on gpu?

Jirka
  • 1,126
  • 6
  • 25