importtensorflow as tf
a = tf.test.is_built_with_cuda() # 判断CUDA是否可以用
b = tf.test.is_gpu_available(
cuda_only=False,
min_cuda_compute_capability=None) # 判断GPU是否可以用
print(a)print(b)
WARNING:tensorflow:From <ipython-input-1-3940d9deed4b>:3: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
True
True
importtensorflow.compat.v1 as tf
tf.disable_v2_behavior()
#Creates a graph.
a = tf.constant([1.0,2.0,3.0,4.0