所以这里是我的代码充分理解:https://hastebin.com/qigimomika.py 。为什么我会得到这个ValueError?
所以基本上我有如下的问题:
位上下文:
def weight_variable(shape):
initial = tensorflow.truncated_normal(shape, stddev=0.01)
return tensorflow.Variable(initial)
def bias_variable(shape):
initial = tensorflow.constant(0.01, shape=shape)
return tensorflow.Variable(initial)
w_layer1 = weight_variable([4, 32])
b_layer1 = bias_variable([32])
input_layer = tensorflow.placeholder("float", [4])
产生错误的行:
h_layer1 = tensorflow.add(tensorflow.matmul(input_layer, w_layer1),b_layer1)
当运行整个代码(这是上面的)它产生以下ValueError
ValueError: Shape must be rank 2 but is rank 1 for 'MatMul' (op: 'MatMul')
with input shapes: [4], [4,32].
现在我的问题:会发生什么,我该如何避免这种情况?
感谢您的关注
编辑:感谢修剪和阿里阿巴斯。
我的解决办法:我改变了input_layer到:
input_layer = tensorflow.placeholder("float", [1, 4])
的问题是,我的第一阵列是tensorflow秩1([4])和我的第二阵列秩2([4,32])。所以我增加这一行:
state = [state]
由此状态的输入是:
output_layer.eval(feed_dict={input_layer : state})
状态最初是[1,2,3,4](等级1),现在它是〔〔1, 2,3,4]](等级2)。
感谢
EDIT2:好吧,我改变了很多,因为最后的编辑。我迷失了记录它们的变化。如果你想看到我的代码here它是。我知道这太麻烦了。现在我只是洙幸福的那些事是工作。“d你就无法理解我的代码是一团糟,但我只是想记录当前状态的大感谢到阿里阿巴斯。:d
欢迎来到StackOverflow。请阅读并遵守帮助文档中的发布准则。 [最小,完整,可验证的示例](http://stackoverflow.com/help/mcve)适用于此处。在发布您的MCVE代码并准确描述问题之前,我们无法为您提供有效的帮助。 我们应该能够将发布的代码粘贴到文本文件中,并重现您描述的问题。 – Prune
感谢您的回复。我改变了一点,所以我希望这样可以。 –
足够接近。我们应该能够将发布的代码粘贴到文本文件中,并重现您描述的问题。对于NN,这应该做。 – Prune