代码1:
import tensorflow as tf
print(tf.test.is_gpu_available())
成功会显示True
代码2:
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"
if __name__ == "__main__":
print(device_lib.list_local_devices())
代码3:
import tensorflow as tf
print(tf.__version__)
成功会显示2.3.0
代码4:
import tensorflow as tf
tensorflow_version = tf.__version__
gpu_available = tf.test.is_gpu_available()
print("tensorflow version:", tensorflow_version, "\tGPU available:", gpu_available)
成功会显示 tensorflow version: 2.3.0 GPU available: True
代码5:
import tensorflow as tf
tf.constant("hello")
成功会显示<tf.Tensor: shape=(), dtype=string, numpy=b'hello'>