0

I first created my TensorFlow code in python on my GPU using :

import tensorflow-gpu as tf

I used it for training purpose and everything went very well. But now, I want to deploy my python scripts on a device without GPU. So, I uninstalled tensorflow-gpu with pip and import normal TensorFlow :

import tensorflow as tf

But when I run the script, it is still using the gpu : enter image description here

I tried this code :

try:
    # Disable all GPUS
    tf.config.set_visible_devices([], 'GPU')
    visible_devices = tf.config.get_visible_devices()
    print(visible_devices)
    for device in visible_devices:
        assert device.device_type != 'GPU'
except Exception as e:
    # Invalid device or cannot modify virtual devices once initialized.
    print(e)

But still not working (even if the gpu seems disable as you can see in white on the screenshot).

I just want to return to the default TensorFlow installation without GPU features. I tried to uninstall and install tensorflow, remove the virtual environment and create a new one, nothing worked.

Thanks for your help !

Eloi
  • 101
  • 10
  • Does this answer your question? [Prevent TensorFlow from accessing the GPU?](https://stackoverflow.com/questions/44552585/prevent-tensorflow-from-accessing-the-gpu) – Vidyadhar Rao Jan 23 '21 at 18:32
  • No, I don't have CUDA_VISIBLE_DEVICES environment variable. And I would prefer to have a non-GPU installation of TensorFlow. – Eloi Jan 23 '21 at 18:39
  • Have you looked at other answers? like .. sess_cpu = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0})) – Vidyadhar Rao Jan 23 '21 at 18:48
  • Alternatively, you could use a virtualenv with non-GPU TensorFlow. – Vidyadhar Rao Jan 23 '21 at 18:51
  • sess_cpu = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0})) does'n work. It raise : AttributeError: module 'tensorflow' has no attribute 'Session' – Eloi Jan 23 '21 at 19:04
  • I have already tried to create a new virtualenv and installed non-gpu tensorflow, but i got the same problem. – Eloi Jan 23 '21 at 19:07
  • You should run your code after ```import tensorflow as tf``` immediately – DachuanZhao Jan 25 '21 at 08:16

0 Answers0