- TensorFlow 2.0 Quick Start Guide
- Tony Holdroyd
- 83字
- 2021-06-24 16:02:02
Using eager execution
Eager execution is the default in TensorFlow 2 and, as such, needs no special setup.
The following code can be used to find out whether a CPU or GPU is in use and if it's a GPU, whether that GPU is #0.
We suggest typing the code in rather than using copy and paste; this way you will get a feel for the commands:
var = tf.Variable([3, 3])
if tf.test.is_gpu_available():
print('Running on GPU')
print('GPU #0?')
print(var.device.endswith('GPU:0'))
else:
print('Running on CPU')