Keras: AttributeError: 'Session' object has no attribute 'list_devices'

Created on 17 Nov 2017  Â·  6Comments  Â·  Source: keras-team/keras

I am getting the error:

using the latest version of keras 2.1.1, I am trying to use the multi_gpu_model fonction and got an error:

so I ran:

from keras import backend as K
K.get_session().list_devices()

I get the error

AttributeErrorTraceback (most recent call last)
<ipython-input-6-0fe3a93aa06e> in <module>()
----> 1 K.get_session().list_devices()

AttributeError: 'Session' object has no attribute 'list_devices'

Also tried following https://github.com/fchollet/keras/pull/8377/files,

from tensorflow.python.client import device_lib
[d.name for d in device_lib.list_local_devices()]

it works fine

Any clues how to solve the problem ?

Most helpful comment

What's your version of TF? I assume you have an outdated version. I would
simply recommend upgrading to 1.4.

On 17 November 2017 at 19:13, TengfeiZhang notifications@github.com wrote:

I also met this problem. What's wrong?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/fchollet/keras/issues/8525#issuecomment-345414334,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AArWb1OiVUIbN7VQ67tdSBz6Xzc2gOrHks5s3ktugaJpZM4QiqmV
.

All 6 comments

I also met this problem. What's wrong?

What's your version of TF? I assume you have an outdated version. I would
simply recommend upgrading to 1.4.

On 17 November 2017 at 19:13, TengfeiZhang notifications@github.com wrote:

I also met this problem. What's wrong?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/fchollet/keras/issues/8525#issuecomment-345414334,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AArWb1OiVUIbN7VQ67tdSBz6Xzc2gOrHks5s3ktugaJpZM4QiqmV
.

How should I upgrade? My current version of 'tensorflow-gpu' is 1.2.0

Francois: Thank you !

adideshpande: Yes you need to upgrade to 1.4. Look at the tensor flow page depending on your OS. for tf 1.4, it will ask you to upgrade cudnn to 6.0...

Hi I am having the same issue:

AttributeError: 'Session' object has no attribute 'list_devices'
Making_A_Prediction_From_Sound.py:155: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (3, 3), activation="relu", data_format="channels_first")`
  model.add(Conv2D(64, (3, 3), activation='relu', dim_ordering="th"))
Traceback (most recent call last):
  File "Making_A_Prediction_From_Sound.py", line 173, in <module>
    model = create_model('/home/pi/Desktop/heart-files/weights-best-031-0.88735.hdf5')
  File "Making_A_Prediction_From_Sound.py", line 155, in create_model
    model.add(Conv2D(64, (3, 3), activation='relu', dim_ordering="th"))
  File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 489, in add
    output_tensor = layer(self.outputs[0])
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 603, in __call__
    output = self.call(inputs, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/keras/layers/convolutional.py", line 164, in call
    dilation_rate=self.dilation_rate)
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 3180, in conv2d
    x, tf_data_format = _preprocess_conv2d_input(x, data_format)
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 3062, in _preprocess_conv2d_input
    if not _has_nchw_support():
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 270, in _has_nchw_support
    gpus_available = len(_get_available_gpus()) > 0
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 256, in _get_available_gpus
    _LOCAL_DEVICES = get_session().list_devices()
AttributeError: 'Session' object has no attribute 'list_devices'

I am following this tutorial:
https://github.com/samjabrahams/tensorflow-on-raspberry-pi/blob/master/GUIDE.md

Which version of tensorflow should I upgrade to and which version of bazel should I use?

Any help would be greatly appreciated!

You should upgrade to TF1.4.

Alternatively, we've added back legacy support for TF1.3 device listing in Keras 2.1.2. So you could also switch to using Keras 2.1.2 if you cannot update your version of TF.

Was this page helpful?
0 / 5 - 0 ratings