9951 explained code solutions for 126 technologies


python-tensorflowHow can I test a Python TensorFlow GPU?


  1. Install TensorFlow GPU on your local machine.
  2. Verify that your system has a compatible GPU with the Nvidia GPU-Driver.
  3. Create a virtual environment with python -m venv <env_name> and activate it with source <env_name>/bin/activate.
  4. Install the TensorFlow GPU version: pip install --upgrade tensorflow-gpu.
  5. Run the following code snippet to check if the installation was successful:
import tensorflow as tf

tf.test.is_gpu_available()

Output example

True

  1. To further test the installation, you can run the following code snippet:
import tensorflow as tf

tf.test.gpu_device_name()

Output example

/device:GPU:0

  1. You can also use the TensorFlow GPU Test to check the installation.

Edit this code on GitHub