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 do I use TensorFlow 1.x with Python?
- How can I use Python and TensorFlow to implement YOLO object detection?
- How do I use the Xception model in TensorFlow with Python?
- How can I use Tensorflow 1.x with Python 3.8?
- How do I install TensorFlow using pip and PyPI?
- How can I use Python and TensorFlow to handle illegal hardware instructions in Zsh?
- How can I use Python TensorFlow in W3Schools?
- How do I check which version of TensorFlow I am using with Python?
- How can I generate a summary of my TensorFlow model in Python?
See more codes...