报错解决:could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED

迈不过友情╰ 2023-06-16 01:56 149阅读 0赞

日萌社" class="reference-link">20191009191333910.png日萌社

人工智能AI:Keras PyTorch MXNet TensorFlow PaddlePaddle 深度学习实战(不定时更新)

#


  1. 执行时报错:could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
  2. 解决方式一:GPU占用问题导致的,keras框架(Tensorflow backend 设置GPU按需分配:
  3. import tensorflow as tf
  4. from keras import backend as K
  5. config = tf.ConfigProto()
  6. config.gpu_options.allow_growth=True
  7. sess = tf.Session(config=config)
  8. K.set_session(sess)
  9. 解决方式二:
  10. physical_devices = tf.config.experimental.list_physical_devices('GPU')
  11. assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
  12. tf.config.experimental.set_memory_growth(physical_devices[0], True)
  13. 解决方式三:
  14. os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
  15. 解决方式四:
  16. """
  17. 0表示指定第一块GPU,1表示指定第二块GPU,以此类推。
  18. 如果只有一块GPU,却指定数字1,并不是0的话,那么会变成使用CPU运行。
  19. """
  20. os.environ['CUDA_VISIBLE_DEVICES'] = '0'

发表评论

表情:
评论列表 (有 0 条评论,149人围观)

还没有评论,来说两句吧...

相关阅读