测试tensorflow是否使用GPU
import tensorflow as tf
version = tf.__version__
gpu_ok = tf.test.is_gpu_available()
print("tf version:",version,"\nuse GPU",gpu_ok)
======================================================================
tensorflow2.0兼容1.x
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
========================================================================
could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
TensorFlow试图分配接近GPU最大内存,一些GPU内存已经被分配给其他东西,分配失败。
config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True))
sess = tf.Session(config=config)
导入tensorflow后,就可以添加了,别添加在with里,只要外面就行。