Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
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 [x.name for x in local_device_protos if x.device_type == 'GPU']

get_available_gpus()


I have the following related modules installed:

pip show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.5.0
Summary: TensorFlow helps the tensors flow
Home-page: https://www.tensorflow.org/
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:

python get_available_gpus.py
Traceback (most recent call last):
  File "get_available_gpus.py", 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)))

    sess.run(tf.initialize_all_variables())

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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...