python-tensorflowHow can I use TensorFlow without a GPU in Python?
TensorFlow can be used without a GPU in Python by using the CPU as the device for computation. To do this, you must set the device
parameter of the tf.Session()
to /cpu:0
when creating the TensorFlow session.
Example code
import tensorflow as tf
# Create the session
sess = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0}))
# Run computation
result = sess.run(...)
Code explanation
import tensorflow as tf
: imports the TensorFlow library.tf.Session()
: creates the session with theconfig
parameter set totf.ConfigProto(device_count={'GPU': 0})
to disable the GPU and use the CPU instead.sess.run(...)
: runs the computation.
Helpful links
More of Python Tensorflow
- How can I use TensorFlow Lite with XNNPACK in Python?
- How do I resolve a SymbolAlreadyExposedError when the symbol "zeros" is already exposed as () in TensorFlow Python util tf_export?
- How can I use YOLOv3 with Python and TensorFlow?
- ¿Cómo implementar reconocimiento facial con TensorFlow y Python?
- How can I use Python and TensorFlow to create an XOR gate?
- How can I use Python and TensorFlow to implement YOLO object detection?
- How can I use Python and TensorFlow to handle illegal hardware instructions in Zsh?
- How can I use Tensorflow 1.x with Python 3.8?
- How do I install Python TensorFlow on Windows?
- How do I check the version of Python Tensorflow I'm using?
See more codes...