标题: Failed to get convolution algorithm解决:keras中model.predict都报错:... [打印本页] 作者: 东方耀 时间: 2020-2-21 12:27 标题: Failed to get convolution algorithm解决:keras中model.predict都报错:... 解决:keras中model.predict都报错:显存不足
Failed to get convolution algorithm.
This is probably because cuDNN failed to initialize,
遇到这样一个问题:
直接用pycharm启动服务 并使用 没问题
但是用终端启动服务,则报错:显存不够 显存明显是够的
报错:Failed to get convolution algorithm. This is probably because cuDNN failed to initialize,
问题一定在:两者启动的环境配置不一样竟然解决了:我看到一个提示说 cudnn一个是7.4.0 一个是7.6.0 说什么不一致 发现我本机安装的是7.4.0
然后我升级为7.6.0 就成功啦! 当然还得加allow_gpu_memory_growth()这个函数 cuda的版本是10.0的
# python 3.6 and tensorflow (both 1.x and 2.0)
def allow_gpu_memory_growth(log_device_placement=True):
"""
Allow dynamic memory growth (by default, tensorflow allocates all gpu memory).
This sometimes fixes the
<<Error : 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>>.
May hurt performance slightly (see https://www.tensorflow.org/guide/gpu).
Usage: Run before any other code.
:param log_device_placement: set True to log device placement (on which device the operation ran)
:return:None
"""
# set_session 标红不用管 Sets the global TensorFlow session
# from tensorflow.compat.v1.keras.backend import set_session
# from tensorflow.python.keras.backend import set_session
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True # dynamically grow the memory used on the GPU
config.log_device_placement = log_device_placement
sess = tf.compat.v1.Session(config=config)
# 一定要拿到全局的session来配置 因为模型预测会用到keras.backend.get_session()
keras.backend.set_session(session=sess)