1. #测试TensorFlow-GPU是否可用
    2. import tensorflow as tf
    3. import os
    4. print(tf.__version__)
    5. os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 不显示等级2以下的提示信息
    6. print('GPU', tf.config.list_physical_devices('GPU'))#列出所有的GPU驱动号
    7. a = tf.constant(2.0)
    8. b = tf.constant(4.0)
    9. print(a + b)

    输出如下:
    图片.png