赞
踩
今天在jupyter notebook中使用keras-gpu时报错,一开始没注意控制台输出,只从jupyter notebook看到了错误信息。于是,查解决方案,大概分为两种,一版本退回,二指定运行设备。因为感觉不是版本的问题,没有退回,仍然用最新的版本,所以尝试第二种方法解决问题,即程序制定运行设备,程序不报错可以跑,无意间注意到控制台输出,发现用的是CPU跑的?然后发现指定设备的名称错误,导致系统找不到设备,于是先查询设备名称再指定设备,解决问题。
本机环境:
Jupyter notebook 打印错误:
...
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 time_distributed_1/convolution (defined at C:\anaconda3\envs\keras\lib\site-packages\keras\backend\tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_1967]
Function call stack:
keras_scratch_graph
Jupyter notebook 控制台打印错误:failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
解决方案:
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
输出:
[name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality { } incarnation: 16677593686354176255, name: "/device:GPU:0" device_type: "GPU" memory_limit: 1440405913 locality { bus_id: 1 links { } } incarnation: 787265797177696422 physical_device_desc: "device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0"]
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '/device:GPU:0'
import tensorflow as tf
sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))
输出:
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。