twnsorflow GPU 版本报错 Blas GEMM launch failed

报错信息

1
2
InternalError (see above for traceback): Blas GEMM launch failed : a.shape=(10000, 784), b.shape=(784, 500), m=10000, n=500, k=784
[[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_Placeholder_0_0/_11, Variable/read)]]

原因

如果你是使用 GPU 版 TensorFlow 的话,并且你想在显卡高占用率的情况下(比如玩游戏)训练模型,那你要注意在初始化 Session 的时候为其分配固定数量的显存,否则可能会在开始训练的时候直接报错退出

解决方案:
需要用下面的方法创建 Session:

1
2
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)  
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

参考资料:
https://segmentfault.com/a/1190000009954640?utm_source=itdadao&utm_medium=referral