aoaoyi 2021-12-14 13:00 采纳率: 0%
浏览 111

mport tensorflow.compat.v1 as tf报错


InvalidArgumentError                      Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1364     try:
-> 1365       return fn(*args)
   1366     except errors.OpError as e:

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
   1348       self._extend_graph()
-> 1349       return self._call_tf_sessionrun(options, feed_dict, fetch_list,
   1350                                       target_list, run_metadata)

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
   1440                           run_metadata):
-> 1441     return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict,
   1442                                             fetch_list, target_list,

InvalidArgumentError: logits and labels must be broadcastable: logits_size=[20,10] labels_size=[1,20]
     [[{{node softmax_cross_entropy_with_logits}}]]

During handling of the above exception, another exception occurred:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-21-9ea56c31ed15> in <module>
      8     for i in range(train_steps):
      9         batch_data, batch_labels = train_data.next_batch(batch_size)
---> 10         loss_val, acc_val, _ = sess.run([loss, accuracy, train_op], feed_dict={x:batch_data, y:batch_labels})
     11         if (i+1) % 500 == 0:
     12             print('[Train] Step: %d, loss: %4.5f, acc: %4.5f'%(i+1, loss_val, acc_val))

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
    955 
    956     try:
--> 957       result = self._run(None, fetches, feed_dict, options_ptr,
    958                          run_metadata_ptr)
    959       if run_metadata:

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1178     # or if the call is a partial run that specifies feeds.
   1179     if final_fetches or final_targets or (handle and feed_dict_tensor):
-> 1180       results = self._do_run(handle, final_targets, final_fetches,
   1181                              feed_dict_tensor, options, run_metadata)
   1182     else:

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1356 
   1357     if handle is None:
-> 1358       return self._do_call(_run_fn, feeds, fetches, targets, options,
   1359                            run_metadata)
   1360     else:

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1382                     '\nsession_config.graph_options.rewrite_options.'
   1383                     'disable_meta_optimizer = True')
-> 1384       raise type(e)(node_def, op, message)
   1385 
   1386   def _extend_graph(self):

InvalidArgumentError: logits and labels must be broadcastable: logits_size=[20,10] labels_size=[1,20]
     [[node softmax_cross_entropy_with_logits (defined at <ipython-input-14-805d31acc86d>:12) ]]

Original stack trace for 'softmax_cross_entropy_with_logits':
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "C:\ProgramData\Anaconda3\lib\site-packages\traitlets\config\application.py", line 845, in launch_instance
    app.start()
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 612, in start
    self.io_loop.start()
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 199, in start
    self.asyncio_loop.run_forever()
  File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
  File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 1859, in _run_once
    handle._run()
  File "C:\ProgramData\Anaconda3\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\ioloop.py", line 688, in <lambda>
    lambda f: self._run_callback(functools.partial(callback, future))
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\ioloop.py", line 741, in _run_callback
    ret = callback()
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 814, in inner
    self.ctx_run(self.run)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 775, in run
    yielded = self.gen.send(value)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 365, in process_one
    yield gen.maybe_future(dispatch(*args))
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 234, in wrapper
    yielded = ctx_run(next, result)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 268, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 234, in wrapper
    yielded = ctx_run(next, result)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 543, in execute_request
    self.do_execute(
  File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 234, in wrapper
    yielded = ctx_run(next, result)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 306, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2894, in run_cell
    result = self._run_cell(
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2940, in _run_cell
    return runner(coro)
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\async_helpers.py", line 68, in _pseudo_sync_runner
    coro.send(None)
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3165, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3357, in run_ast_nodes
    if (await self.run_code(code, result,  async_=asy)):
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3437, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-14-805d31acc86d>", line 12, in <module>
    loss=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=y_),name='loss')
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\util\dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 3799, in softmax_cross_entropy_with_logits_v2
    return softmax_cross_entropy_with_logits_v2_helper(
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\util\dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\util\deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 3901, in softmax_cross_entropy_with_logits_v2_helper
    cost, unused_backprop = gen_nn_ops.softmax_cross_entropy_with_logits(
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 10886, in softmax_cross_entropy_with_logits
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 742, in _apply_op_helper
    op = g._create_op_internal(op_type_name, inputs, dtypes=None,
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 3477, in _create_op_internal
    ret = Operation(
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1949, in __init__
    self._traceback = tf_stack.extract_stack()
  • 写回答

1条回答 默认 最新

  • 爱晚乏客游 2021-12-14 14:02
    关注

    import tensorflow._api.v2.compat.v1 as tf

    评论

报告相同问题?

问题事件

  • 创建了问题 12月14日

悬赏问题

  • ¥15 疾病的获得与年龄是否有关
  • ¥15 关于浏览器控制台js报错问题-swiper.js相关
  • ¥15 opencv.js内存,CPU飙升
  • ¥15 植物重测序snp数据Treemix分析出现问题!
  • ¥15 怎么让当前页面只能有一人在编辑
  • ¥15 UCOSⅢ,3.0.3升级为3.0.4后程序编译成功,但是运行后死在统计任务的地方
  • ¥15 python程序长时间运行卡死,付费求解决方案
  • ¥20 VM打开不了ubuntu虚拟机,如何解决?
  • ¥15 java请求一个返回流式数据的接口,如何将流式数据直接返回前端
  • ¥15 为什么连接不了啊,配置都没问题啊