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 the Xception model in TensorFlow with Python?
- How can I access the 'inputs' attribute in the 'tensorflow_estimator.python.estimator.api._v2.estimator' module?
- How can I convert a Tensor object to a list in Python using TensorFlow?
- How do I install TensorFlow using pip and PyPI?
- How can I use Tensorflow 1.x with Python 3.8?
- How can I test my GPU performance with Python and TensorFlow?
- How can I install and use Python TensorFlow on an Apple M1 Mac?
- How do I resolve the "no module named 'tensorflow.python.keras.preprocessing'" error?
- How do I use TensorFlow 1.x with Python?
See more codes...