深度学习框架 坑点集中贴 (持续更新)

坑点一: Tensorflow 卷积报错

  1. 详细描述: RTX2070 + 驱动 410 + cuda 10.0 + cudnn 7.5.0 环境

  2. 报错内容: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.
    Tensorflow 1.3+ Tensorflow2.0 均会报错

  3. 报错原因推测: tensorflow cudnn cuda 版本不协调,降级是一个解决办法,比如降到 cuda9 ,tensorflow降低 1.9, 但是毕竟不能使用新版本。 若使用2.0 版本,即使降低cudnn到7.4,依然会报错,再将版本已然不能满足版本需求。

  4. 解决方案:1) 对于 Tensorflow1.13+ ,使用session的情况,不使用estimator
    在定义session前添加:

      session_conf = tf.ConfigProto(allow_soft_placement=True, log_device_placement=False)
     session_conf.gpu_options.allow_growth=True
     session_conf.gpu_options.per_process_gpu_memory_fraction = 0.9  # 配置gpu占用率  
     sess = tf.Session(config=session_conf)
    

    2) 对于 Tensorflow1.13+ ,使用estimator
    在文件开头添加:

from tensorflow import ConfigProto
from tensorflow import InteractiveSession
config = ConfigProto()
config.gpu_options.allow_growth = True
#session = InteractiveSession(config=config)
run_config = tf.estimator.RunConfig().replace(session_config=config)

并在模型训练时候,添加相应run_config参数,以IMDB的textcnn模型为例子:

imdb_classifier = tf.estimator.Estimator(model_fn=cnn_model_fn,model_dir="imdb_model_textcnn",config=run_config)

3)对于1.13+, 使用 keras

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
tf.keras.backend.set_session(tf.Session(config=config))

4)使用eager execution

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
tf.enable_eager_execution(config=config)

5)tensorflow 2.0

physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
tf.config.experimental.set_memory_growth(physical_devices[0], True)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值