Tensorflow中使用CPU及GPU的参数设置
在进行SVM机器学习训练时,报dst Tensorflow is not initialized错误,为显存使用溢出错误。解决方式为使用CPU或者限制GPU显存。
1、设置使用GPU还是CPU:
import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
2、安装GPU版本Tensorflow,只有一个GPU的情况下,"0"默认为GPU,"1"将使用CPU
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.7 #使用GPU显存的比率
config.gpu_options.allow_growth =True #按需求使用GPU
with tf.Session(config=config) as sess: #或sess = tf.Session(config=config)