Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (11.4k points)

I'm trying to run a simple python script that uses Tensorflow to print the available GPU devices. The script is

from tensorflow.python.client import device_lib

def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [ for x in local_device_protos if x.device_type == 'GPU']


I have the following related modules installed:

pip show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.5.0
Summary: TensorFlow helps the tensors flow
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python3.5/dist-packages
Requires: wheel, six, tensorflow-tensorboard, numpy, absl-py, protobuf

However, when I run the script I get the following error:

Traceback (most recent call last):
  File "", line 2, in <module>
    from tensorflow.python.client import device_lib
ImportError: No module named tensorflow.python.client


1 Answer

0 votes
by (32.3k points)

According to me, it is a bug in Tensorflow and you should open a bug thread about it.

In any case, to work around this issue, you can use tf.identity to create a float64_ref instead of the float64 x and pass this value as the inputs parameter.

import tensorflow as tf

import numpy as np

with tf.Session() as sess:

    x = tf.Variable(np.ones((2, 3)))

    out, state = tf.nn.rnn_cell.BasicRNNCell(4)(tf.identity(x), x)

Browse Categories