前言
记录下一些小问题的解决方案(长期更新)。
tensorflow和keras限制gpu显存
tensorflow
ps:注意keras和tensorflow设置方式是不同的
限制为0.5
import tensorflow
tf_config = tensorflow.ConfigProto()
tf_config.gpu_options.per_process_gpu_memory_fraction = 0.5 # 分配50%
session = tensorflow.Session(config=tf_config)
- 1
- 2
- 3
- 4
自适应最佳
tf_config = tensorflow.ConfigProto()
tf_config.gpu_options.allow_growth = True
session = tensorflow.Session(config=tf_config)
- 1
- 2
- 3
keras
import keras
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
set_session(tf.Session(config=config))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
设置tensorflow和keras设置cpu运行
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
- 1
- 2
- 3
常见异常解决方案
这种异常我个人认为是tensorflow版本导致
tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above. [[{{node Conv/convolution}}]] [[{{node metrics/_f_score/Identity}}]]
- 1
- 2
- 3
- 4
解决方法:
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)
- 1
- 2
- 3
- 4
文章来源: blog.csdn.net,作者:快了的程序猿小可哥,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_35914625/article/details/108692540