python-tensorflowHow do I use Python TensorFlow with a CUDA-enabled GPU?
Using Python TensorFlow with a CUDA-enabled GPU requires several steps:
- Install the CUDA Toolkit, which includes the CUDA Driver and other tools.
- Install the NVIDIA CUDA Deep Neural Network library (cuDNN).
- Install the Python development environment.
- Install TensorFlow using
pip install tensorflow-gpu
. - Check if GPU is detected by running the following code:
import tensorflow as tf
tf.test.is_gpu_available()
Output example
True
- Now you can use TensorFlow with a CUDA-enabled GPU. For example:
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
Output example
[[22. 28.]
[49. 64.]]
Helpful links
More of Python Tensorflow
- How can I check the compatibility of different versions of Python and TensorFlow?
- ¿Cómo implementar reconocimiento facial con TensorFlow y Python?
- How can I use TensorFlow Lite with XNNPACK in Python?
- How do I install Tensorflow with a Python wheel (whl) file?
- How do I check which version of TensorFlow I am using with Python?
- How do I uninstall Python TensorFlow?
- How do I use Python and TensorFlow Placeholders?
- How can I use Python and TensorFlow to handle illegal hardware instructions in Zsh?
- 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 implement YOLO object detection?
See more codes...