測試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裏,只要外面就行。