猿问

InvalidArgumentError:找到 2 个根错误。Tensorflow

我正在尝试从以下repo中获取代码,该 repo基于本文。它有很多错误,但我大部分都能正常工作。但是,我一直遇到同样的问题,我真的不明白如何解决这个问题/甚至出了什么问题。

该错误在第二次验证 if 语句标准时发生。第一次总是有效,然后在第二次中断。如果它有帮助,我将包括它在中断之前打印的输出


慕田峪4524236
浏览 546回答 2
2回答

胡说叔叔

介绍我认为主要问题是您提供的数组(或矩阵或其他结构)大小的数据不匹配sess.run。特别是当你打电话时:train_loss, train_accuracy, _ = sess.run([model.loss, model.accuracy,model.train_op], feed_dict = {model.word_ids: word_idss, model.utterance_lengths: utterance_lengthss, model.dialogue_lengths: dialogue_lengthss, model.labels:labs_t, model.clip :clip} )更具体地说,这里的这个错误暗示这是一个不匹配的问题:tensorflow.python.framework.errors_impl.InvalidArgumentError:&nbsp;indices[317]&nbsp;=&nbsp;[317,&nbsp;-1]&nbsp;does&nbsp;not&nbsp;index&nbsp;into&nbsp;param&nbsp;shape&nbsp;[318,39,400] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[[{{node&nbsp;utterance_encoder/GatherNd}}]]我认为也许在全新安装上运行可能会导致无错误运行。我收到了类似的错误,但也收到了完整的警告列表。请注意我在 Windows 7 上运行并使用 python 3.6.1。版本我尝试了以下 tensorflow 版本,但没有成功:TF 1.15TF 1.14TF 1.13.1TF 1.12TF 1.11TF 1.10tf 1.10 将 keras 降级到 2.2.1脚步安装了 python 3.6.1(支持的 tensorflow 版本)。为所有用户安装。设置路径。安装在 C:\Python36pip3 install --user --upgrade tensorflow==1.15pip3 install --user --upgrade pandas == 0.25.3pip3 install --user --upgrade numpy == 1.17.5下载以下内容:https ://github.com/cmeaton/Hierarchical_BiLSTM-CRF_Encoder/tree/master/swda_parsed运行提供的代码结果(包括许多警告)我认为以下可能很重要:tensorflow.python.framework.errors_impl.InvalidArgumentError:&nbsp;indices[317]&nbsp;=&nbsp;[317,&nbsp;-1]&nbsp;does&nbsp;not&nbsp;index&nbsp;into&nbsp;param&nbsp;shape&nbsp;[318,39,400] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[[{{node&nbsp;utterance_encoder/GatherNd}}]]全跟踪WARNING:tensorflow:From test.py:313: The name tf.reset_default_graph is deprecated. Please use tf.compat.v1.reset_default_graph instead.WARNING:tensorflow:From test.py:256: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.WARNING:tensorflow:From test.py:259: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.2020-01-31 12:13:10.096283: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2WARNING:tensorflow:From test.py:119: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.WARNING:tensorflow:From test.py:121: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.WARNING:tensorflow:From test.py:130: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.WARNING:tensorflow:From test.py:137: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.Instructions for updating:Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.WARNING:tensorflow:From test.py:147: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.Instructions for updating:This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.WARNING:tensorflow:From test.py:150: bidirectional_dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.Instructions for updating:Please use `keras.layers.Bidirectional(keras.layers.RNN(cell))`, which is equivalent to this APIWARNING:tensorflow:From D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\ops\rnn.py:464: dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.Instructions for updating:Please use `keras.layers.RNN(cell)`, which is equivalent to this APIWARNING:tensorflow:From D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\ops\rnn_cell_impl.py:958: Layer.add_variable (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version.Instructions for updating:Please use `layer.add_weight` method instead.WARNING:tensorflow:From D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\ops\rnn_cell_impl.py:962: calling Zeros.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.Instructions for updating:Call initializer instance with the dtype argument instead of passing it to the constructorWARNING:tensorflow:From D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\ops\rnn.py:244: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.Instructions for updating:Use tf.where in 2.0, which has the same broadcast rule as np.whereWARNING:tensorflow:The TensorFlow contrib module will not be included in TensorFlow 2.0.For more information, please see:&nbsp; * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md&nbsp; * https://github.com/tensorflow/addons&nbsp; * https://github.com/tensorflow/io (for I/O related ops)If you depend on functionality not listed there, please file an issue.WARNING:tensorflow:From test.py:163: BasicLSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.Instructions for updating:This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.WARNING:tensorflow:From test.py:223: The name tf.train.AdagradOptimizer is deprecated. Please use tf.compat.v1.train.AdagradOptimizer instead.WARNING:tensorflow:From D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\training\adagrad.py:76: calling Constant.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.Instructions for updating:Call initializer instance with the dtype argument instead of passing it to the constructorWARNING:tensorflow:From test.py:261: The name tf.global_variables_initializer is deprecated. Please use tf.compat.v1.global_variables_initializer instead.WARNING:tensorflow:From test.py:263: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.WARNING:tensorflow:From test.py:265: The name tf.summary.FileWriter is deprecated. Please use tf.compat.v1.summary.FileWriter instead.2020-01-31 12:13:16.563989: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at gather_nd_op.cc:47 : Invalid argument: indices[317] = [317, -1] does not index into param shape [318,39,400]Traceback (most recent call last):&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\client\session.py", line 1365, in _do_call&nbsp; &nbsp; return fn(*args)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\client\session.py", line 1350, in _run_fn&nbsp; &nbsp; target_list, run_metadata)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\client\session.py", line 1443, in _call_tf_sessionrun&nbsp; &nbsp; run_metadata)tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[317] = [317, -1] does not index into param shape [318,39,400]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[[{{node utterance_encoder/GatherNd}}]]During handling of the above exception, another exception occurred:Traceback (most recent call last):&nbsp; File "test.py", line 314, in <module>&nbsp; &nbsp; main()&nbsp; File "test.py", line 274, in main&nbsp; &nbsp; train_loss, train_accuracy, _ = sess.run([model.loss, model.accuracy,model.train_op], feed_dict = {model.word_ids: word_idss, model.utterance_lengths: utterance_lengthss, model.dialogue_lengths: dialogue_lengthss, model.labels:labs_t, model.clip :clip} )&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\client\session.py", line 956, in run&nbsp; &nbsp; run_metadata_ptr)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\client\session.py", line 1180, in _run&nbsp; &nbsp; feed_dict_tensor, options, run_metadata)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\client\session.py", line 1359, in _do_run&nbsp; &nbsp; run_metadata)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\client\session.py", line 1384, in _do_call&nbsp; &nbsp; raise type(e)(node_def, op, message)tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[317] = [317, -1] does not index into param shape [318,39,400]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[[node utterance_encoder/GatherNd (defined at D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\framework\ops.py:1748) ]]Original stack trace for 'utterance_encoder/GatherNd':&nbsp; File "test.py", line 314, in <module>&nbsp; &nbsp; main()&nbsp; File "test.py", line 260, in main&nbsp; &nbsp; model = DAModel()&nbsp; File "test.py", line 155, in __init__&nbsp; &nbsp; output = select(output, length) # [batch_size, dim]&nbsp; File "test.py", line 114, in select&nbsp; &nbsp; return tf.gather_nd(parameters, idx)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\util\dispatch.py", line 180, in wrapper&nbsp; &nbsp; return target(*args, **kwargs)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\ops\array_ops.py", line 4277, in gather_nd&nbsp; &nbsp; return gen_array_ops.gather_nd(params, indices, name=name)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\ops\gen_array_ops.py", line 3975, in gather_nd&nbsp; &nbsp; "GatherNd", params=params, indices=indices, name=name)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\framework\op_def_library.py", line 794, in _apply_op_helper&nbsp; &nbsp; op_def=op_def)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\util\deprecation.py", line 507, in new_func&nbsp; &nbsp; return func(*args, **kwargs)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\framework\ops.py", line 3357, in create_op&nbsp; &nbsp; attrs, op_def, compute_device)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\framework\ops.py", line 3426, in _create_op_internal&nbsp; &nbsp; op_def=op_def)&nbsp; File "D:\Users\bakopme\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\framework\ops.py", line 1748, in __init__&nbsp; &nbsp; self._traceback = tf_stack.extract_stack()

函数式编程

让我们关注错误:Invalid&nbsp;argument:&nbsp;Incompatible&nbsp;shapes:&nbsp;[2,185]&nbsp;vs.&nbsp;[2,229]问题似乎是两个张量之间的运算失败,因为它们的形状不兼容。tensorflow您选择的版本可能比作者使用的版本更宽松。根据这个问题,作者猜测他是用的tensorflow==1.8。所以首先我建议你尝试使用这个早期版本,或者之前\之后的其他版本(1.7、1.9、1.10 等)。此外,早期版本可能没有keras像现在这样集成到它们的包,因此您可能还想使用特定keras版本。例如根据这个问题,有帮助的是降级到keras==2.2.2.如果这没有帮助,也许其中之一会:1&nbsp;,&nbsp;2&nbsp;,&nbsp;3&nbsp;,&nbsp;4&nbsp;,&nbsp;5&nbsp;,&nbsp;6
随时随地看视频慕课网APP

相关分类

Python
我要回答