python-tensorflowHow can I check if my Python TensorFlow code is using the GPU?
To check if your Python TensorFlow code is using the GPU, you can use the tf.test.is_gpu_available()
method. This will return True
if a GPU is available and False
if it isn't.
Example
import tensorflow as tf
tf.test.is_gpu_available()
Output example
True
You can also use the tf.config.list_physical_devices('GPU')
method to list the physical GPUs available.
Example
import tensorflow as tf
tf.config.list_physical_devices('GPU')
Output example
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
You can also use the tf.config.experimental.list_physical_devices('GPU')
method to list the physical GPUs available.
Example
import tensorflow as tf
tf.config.experimental.list_physical_devices('GPU')
Output example
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
If you want to check which device your code is running on, you can use the tf.config.list_logical_devices()
method. This will list the available devices, including CPUs and GPUs.
Example
import tensorflow as tf
tf.config.list_logical_devices()
Output example
[LogicalDevice(name='/device:CPU:0', device_type='CPU'), LogicalDevice(name='/device:GPU:0', device_type='GPU')]
Helpful links
More of Python Tensorflow
- How do I resolve a SymbolAlreadyExposedError when the symbol "zeros" is already exposed as () in TensorFlow Python util tf_export?
- How can I use Python and TensorFlow to handle illegal hardware instructions in Zsh?
- ¿Cómo implementar reconocimiento facial con TensorFlow y Python?
- How do I use TensorFlow 1.x with Python?
- How do I use the Xception model in TensorFlow with Python?
- How can I use YOLOv3 with Python and TensorFlow?
- How can I use Python and TensorFlow to implement YOLOv4?
- How do I use Python TensorFlow 1.x?
- How can I use TensorFlow Lite with XNNPACK in Python?
- How can I use Tensorflow 1.x with Python 3.8?
See more codes...