CUDNN_STATUS_NOT_INITIALIZED

栏目: Python · 发布时间: 6年前

内容简介:自从装好tensorflow-gpu 之后其实一直没怎么用,今天跑代码的时候才发现安装的有问题:测试代码如下:虽然代码比较简单,但是运行却出现了问题,报了一大堆错误:

自从装好tensorflow-gpu 之后其实一直没怎么用,今天跑代码的时候才发现安装的有问题:

测试代码如下:

from sklearn.datasets import load_sample_image
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
 
if __name__ == '__main__':
    # Load sample images
    china = load_sample_image("china.jpg")
    flower = load_sample_image("flower.jpg")
    dataset = np.array([china, flower], dtype=np.float32)
    batch_size, height, width, channels = dataset.shape
    # Create 2 filters
    filters = np.zeros(shape=(7, 7, channels, 2), dtype=np.float32)
    filters[:, 3, :, 0] = 1 # vertical line
    filters[3, :, :, 1] = 1 # horizontal line
    # Create a graph with input X plus a convolutional layer applying the 2 filters
    X = tf.placeholder(tf.float32, shape=(None, height, width, channels))
    convolution = tf.nn.conv2d(X, filters, strides=[1,2,2,1], padding="SAME")
    with tf.Session() as sess:
        output = sess.run(convolution, feed_dict={X: dataset})
    plt.imshow(output[0, :, :, 1], cmap="gray") # plot 1st image's 2nd feature map
    plt.show()

虽然代码比较简单,但是运行却出现了问题,报了一大堆错误:

---------------------------------------------------------------------------
UnknownError                              Traceback (most recent call last)
d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1333     try:
-> 1334       return fn(*args)
   1335     except errors.OpError as e:
 
d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\client\session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
   1318       return self._call_tf_sessionrun(
-> 1319           options, feed_dict, fetch_list, target_list, run_metadata)
   1320 
 
d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\client\session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
   1406         self._session, options, feed_dict, fetch_list, target_list,
-> 1407         run_metadata)
   1408 
 
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 Conv2D_1}} = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 2, 2, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_Placeholder_1_0_0/_1, Conv2D_1/filter)]]
	 [[{{node Conv2D_1/_3}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_7_Conv2D_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
 
During handling of the above exception, another exception occurred:
 
UnknownError                              Traceback (most recent call last)
<ipython -input-2-e2c684c672f5> in <module>
     18     convolution = tf.nn.conv2d(X, filters, strides=[1,2,2,1], padding="SAME")
     19     with tf.Session() as sess:
---> 20         output = sess.run(convolution, feed_dict={X: dataset})
     21     plt.imshow(output[0, :, :, 1], cmap="gray") # plot 1st image's 2nd feature map
     22     plt.show()
 
d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
    927     try:
    928       result = self._run(None, fetches, feed_dict, options_ptr,
--> 929                          run_metadata_ptr)
    930       if run_metadata:
    931         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
 
d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1150     if final_fetches or final_targets or (handle and feed_dict_tensor):
   1151       results = self._do_run(handle, final_targets, final_fetches,
-> 1152                              feed_dict_tensor, options, run_metadata)
   1153     else:
   1154       results = []
 
d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1326     if handle is None:
   1327       return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1328                            run_metadata)
   1329     else:
   1330       return self._do_call(_prun_fn, handle, feeds, fetches)
 
d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1346           pass
   1347       message = error_interpolation.interpolate(message, self._graph)
-> 1348       raise type(e)(node_def, op, message)
   1349 
   1350   def _extend_graph(self):
 
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 Conv2D_1 (defined at <ipython -input-2-e2c684c672f5>:18)  = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 2, 2, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_Placeholder_1_0_0/_1, Conv2D_1/filter)]]
	 [[{{node Conv2D_1/_3}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_7_Conv2D_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
 
Caused by op 'Conv2D_1', defined at:
  File "E:\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "E:\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\machinelinerningproject\venv36\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "d:\machinelinerningproject\venv36\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "d:\machinelinerningproject\venv36\lib\site-packages\ipykernel\kernelapp.py", line 505, in start
    self.io_loop.start()
  File "d:\machinelinerningproject\venv36\lib\site-packages\tornado\platform\asyncio.py", line 132, in start
    self.asyncio_loop.run_forever()
  File "E:\Python36\lib\asyncio\base_events.py", line 438, in run_forever
    self._run_once()
  File "E:\Python36\lib\asyncio\base_events.py", line 1451, in _run_once
    handle._run()
  File "E:\Python36\lib\asyncio\events.py", line 145, in _run
    self._callback(*self._args)
  File "d:\machinelinerningproject\venv36\lib\site-packages\tornado\ioloop.py", line 758, in _run_callback
    ret = callback()
  File "d:\machinelinerningproject\venv36\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
    return fn(*args, **kwargs)
  File "d:\machinelinerningproject\venv36\lib\site-packages\tornado\gen.py", line 1233, in inner
    self.run()
  File "d:\machinelinerningproject\venv36\lib\site-packages\tornado\gen.py", line 1147, in run
    yielded = self.gen.send(value)
  File "d:\machinelinerningproject\venv36\lib\site-packages\ipykernel\kernelbase.py", line 357, in process_one
    yield gen.maybe_future(dispatch(*args))
  File "d:\machinelinerningproject\venv36\lib\site-packages\tornado\gen.py", line 326, in wrapper
    yielded = next(result)
  File "d:\machinelinerningproject\venv36\lib\site-packages\ipykernel\kernelbase.py", line 267, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "d:\machinelinerningproject\venv36\lib\site-packages\tornado\gen.py", line 326, in wrapper
    yielded = next(result)
  File "d:\machinelinerningproject\venv36\lib\site-packages\ipykernel\kernelbase.py", line 534, in execute_request
    user_expressions, allow_stdin,
  File "d:\machinelinerningproject\venv36\lib\site-packages\tornado\gen.py", line 326, in wrapper
    yielded = next(result)
  File "d:\machinelinerningproject\venv36\lib\site-packages\ipykernel\ipkernel.py", line 294, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "d:\machinelinerningproject\venv36\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "d:\machinelinerningproject\venv36\lib\site-packages\IPython\core\interactiveshell.py", line 2819, in run_cell
    raw_cell, store_history, silent, shell_futures)
  File "d:\machinelinerningproject\venv36\lib\site-packages\IPython\core\interactiveshell.py", line 2845, in _run_cell
    return runner(coro)
  File "d:\machinelinerningproject\venv36\lib\site-packages\IPython\core\async_helpers.py", line 67, in _pseudo_sync_runner
    coro.send(None)
  File "d:\machinelinerningproject\venv36\lib\site-packages\IPython\core\interactiveshell.py", line 3020, in run_cell_async
    interactivity=interactivity, compiler=compiler, result=result)
  File "d:\machinelinerningproject\venv36\lib\site-packages\IPython\core\interactiveshell.py", line 3185, in run_ast_nodes
    if (yield from self.run_code(code, result)):
  File "d:\machinelinerningproject\venv36\lib\site-packages\IPython\core\interactiveshell.py", line 3267, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython -input-2-e2c684c672f5>", line 18, in <module>
    convolution = tf.nn.conv2d(X, filters, strides=[1,2,2,1], padding="SAME")
  File "d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 1044, in conv2d
    data_format=data_format, dilations=dilations, name=name)
  File "d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\framework\ops.py", line 3274, in create_op
    op_def=op_def)
  File "d:\machinelinerningproject\venv36\lib\site-packages\tensorflow\python\framework\ops.py", line 1770, in __init__
    self._traceback = tf_stack.extract_stack()
 
UnknownError (see above for traceback): 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 Conv2D_1 (defined at <ipython -input-2-e2c684c672f5>:18)  = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 2, 2, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_Placeholder_1_0_0/_1, Conv2D_1/filter)]]
	 [[{{node Conv2D_1/_3}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_7_Conv2D_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
 
 
</ipython></module></ipython></module></ipython></module></ipython>

网上搜索了一下解决方案,但是并不是很好用。最后尝试了如下方法

  1. 安装cuda_9.0 补丁包,链接地址: https://developer.nvidia.com/cuda-90-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal
  2. 更新显卡驱动程序,原来为395,现在更新到了419.17

CUDNN_STATUS_NOT_INITIALIZED

原创文章,转载请注明:转载自obaby@mars

本文标题: 《CUDNN_STATUS_NOT_INITIALIZED》

本文链接地址: http://www.h4ck.org.cn/2019/03/cudnn_status_not_initialized/

CUDNN_STATUS_NOT_INITIALIZED


以上所述就是小编给大家介绍的《CUDNN_STATUS_NOT_INITIALIZED》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Build Your Own Web Site the Right Way Using HTML & CSS

Build Your Own Web Site the Right Way Using HTML & CSS

Ian Lloyd / SitePoint / 2006-05-02 / USD 29.95

Build Your Own Website The Right Way Using HTML & CSS teaches web development from scratch, without assuming any previous knowledge of HTML, CSS or web development techniques. This book introduces you......一起来看看 《Build Your Own Web Site the Right Way Using HTML & CSS》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换