Tensorflow的“ Blas GEMM启动失败”错误是什么意思?

时间:2018-12-02 21:02:05

标签: python python-3.x tensorflow

我正在学习读一本韩国书的tensorflow。 我只是复制并粘贴了本书的代码 但是这段代码显示了错误消息。 我想找到有关此消息的信息,但是即使我也看不到应该找到哪条消息。 谁能帮我...?

这是代码。 (使用jupyter笔记本)

import tensorflow as tf
import numpy as np

x_data = np.array(
    [[0, 0], [1, 0], [1, 1], [0, 0], [0, 0], [0, 1]])

y_data = np.array([
    [1, 0, 0],  # 기타
    [0, 1, 0],  # 포유류
    [0, 0, 1],  # 조류
    [1, 0, 0],
    [1, 0, 0],
    [0, 0, 1]
])

X = tf.placeholder(tf.float32)
Y = tf.placeholder(tf.float32)

W1 = tf.Variable(tf.random_uniform([2, 10], -1., 1.))
W2 = tf.Variable(tf.random_uniform([10, 3], -1., 1.))

b1 = tf.Variable(tf.zeros([10]))
b2 = tf.Variable(tf.zeros([3]))

L1 = tf.add(tf.matmul(X, W1), b1)
L1 = tf.nn.relu(L1)

model = tf.add(tf.matmul(L1, W2), b2)

cost = tf.reduce_mean(
    tf.nn.softmax_cross_entropy_with_logits_v2(labels=Y, logits=model))

optimizer = tf.train.AdamOptimizer(learning_rate=0.01)
train_op = optimizer.minimize(cost)

直到这里没有错误,但是代码从下面的单元格发出了错误消息。

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

for step in range(100):
    sess.run(train_op, feed_dict={X: x_data, Y: y_data})

    if (step + 1) % 10 == 0:
        print(step + 1, sess.run(cost, feed_dict={X: x_data, Y: y_data}))

InternalError                             Traceback (most recent call last)
c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1321     try:
-> 1322       return fn(*args)
   1323     except errors.OpError as e:

c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\client\session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
   1306       return self._call_tf_sessionrun(
-> 1307           options, feed_dict, fetch_list, target_list, run_metadata)
   1308 

c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\client\session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
   1408           self._session, options, feed_dict, fetch_list, target_list,
-> 1409           run_metadata)
   1410     else:

InternalError: Blas GEMM launch failed : a.shape=(6, 2), b.shape=(2, 10), m=6, n=10, k=2
     [[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_Placeholder_0_0/_3, Variable/read)]]

During handling of the above exception, another exception occurred:

InternalError                             Traceback (most recent call last)
<ipython-input-7-2e54042a3fcf> in <module>
      4 
      5 for step in range(100):
----> 6     sess.run(train_op, feed_dict={X: x_data, Y: y_data})
      7 
      8     if (step + 1) % 10 == 0:

c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
    898     try:
    899       result = self._run(None, fetches, feed_dict, options_ptr,
--> 900                          run_metadata_ptr)
    901       if run_metadata:
    902         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1133     if final_fetches or final_targets or (handle and feed_dict_tensor):
   1134       results = self._do_run(handle, final_targets, final_fetches,
-> 1135                              feed_dict_tensor, options, run_metadata)
   1136     else:
   1137       results = []

c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1314     if handle is None:
   1315       return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1316                            run_metadata)
   1317     else:
   1318       return self._do_call(_prun_fn, handle, feeds, fetches)

c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1333         except KeyError:
   1334           pass
-> 1335       raise type(e)(node_def, op, message)
   1336 
   1337   def _extend_graph(self):

InternalError: Blas GEMM launch failed : a.shape=(6, 2), b.shape=(2, 10), m=6, n=10, k=2
     [[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_Placeholder_0_0/_3, Variable/read)]]

Caused by op 'MatMul', defined at:
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\ipykernel\kernelapp.py", line 505, in start
    self.io_loop.start()
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tornado\platform\asyncio.py", line 127, in start
    self.asyncio_loop.run_forever()
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\asyncio\base_events.py", line 421, in run_forever
    self._run_once()
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\asyncio\base_events.py", line 1425, in _run_once
    handle._run()
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\asyncio\events.py", line 127, in _run
    self._callback(*self._args)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tornado\ioloop.py", line 759, in _run_callback
    ret = callback()
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
    return fn(*args, **kwargs)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tornado\gen.py", line 1199, in inner
    self.run()
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tornado\gen.py", line 1113, in run
    yielded = self.gen.send(value)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\ipykernel\kernelbase.py", line 357, in process_one
    yield gen.maybe_future(dispatch(*args))
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tornado\gen.py", line 315, in wrapper
    yielded = next(result)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\ipykernel\kernelbase.py", line 267, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tornado\gen.py", line 315, in wrapper
    yielded = next(result)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\ipykernel\kernelbase.py", line 534, in execute_request
    user_expressions, allow_stdin,
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tornado\gen.py", line 315, in wrapper
    yielded = next(result)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\ipykernel\ipkernel.py", line 294, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\IPython\core\interactiveshell.py", line 2819, in run_cell
    raw_cell, store_history, silent, shell_futures)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\IPython\core\interactiveshell.py", line 2845, in _run_cell
    return runner(coro)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\IPython\core\async_helpers.py", line 67, in _pseudo_sync_runner
    coro.send(None)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\IPython\core\interactiveshell.py", line 3020, in run_cell_async
    interactivity=interactivity, compiler=compiler, result=result)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\IPython\core\interactiveshell.py", line 3185, in run_ast_nodes
    if (yield from self.run_code(code, result)):
  File "c:\programdata\anaconda3\envs\ilovemeat\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-4-4ad5b6dffb7c>", line 1, in <module>
    L1 = tf.add(tf.matmul(X, W1), b1)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\ops\math_ops.py", line 2122, in matmul
    a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\ops\gen_math_ops.py", line 4567, in mat_mul
    name=name)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\framework\ops.py", line 3392, in create_op
    op_def=op_def)
  File "c:\programdata\anaconda3\envs\ilovemeat\lib\site-packages\tensorflow\python\framework\ops.py", line 1718, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InternalError (see above for traceback): Blas GEMM launch failed : a.shape=(6, 2), b.shape=(2, 10), m=6, n=10, k=2
     [[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_Placeholder_0_0/_3, Variable/read)]]

谁能告诉我问题出在哪里...? 我想知道错误消息是否难以阅读,所以我将其图片放在这里。

Message

Message

Message

最后一个单元格如下所示。谢谢您的帮助!!

prediction = tf.argmax(model, 1)
target = tf.argmax(Y, 1)
print('prediction:', sess.run(prediction, feed_dict={X: x_data}))
print('real value:', sess.run(target, feed_dict={Y: y_data}))

is_correct = tf.equal(prediction, target)
accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32))
print('accuracy: %.2f' % sess.run(accuracy * 100, feed_dict={X: x_data, Y: y_data}))

1 个答案:

答案 0 :(得分:0)

几天过去了,没有答案,所以我自己写下来。 我关闭了所有笔记本和控制台提示窗口,重新启动了jupyter笔记本,它正常工作。 我认为问题出在连接方面。