# 安装
pip install tensorflow-gpu==2.5.0
测试:
# 查看tf版本
import tensorflow as tf
print(tf.__version__)
# 查看主机上运行的设备
import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
print(gpus)
print(cpus)
# 查看GPU是否可用,指定在CPU/GPU上运行
import tensorflow as tf
# 指定在cpu上运行
with tf.device('/cpu:0')