所以我對張量流是新的,我的錯誤是,我在餵養 對train_neural_network(x)x無效的參數。Tensorflow session.run飼料字典機制
我想要做的是4999次迭代,輸入一個[1,400]數組是 圖片的位值。所以輸入4999張照片。我用 scipy.io作爲矩陣而不是張量讀取圖像。
我對如何使用佔位符以及我的代碼通常有什麼問題感到困惑。因爲我提供x和y的佔位符,不應該輸入x到train_neural_network(x)是佔位符值嗎?
X = tf.placeholder( '浮動',[1400]) Y = tf.placeholder( '浮動',[1,10])
DEF neural_network_model(數據):
hidden_layer1 = {'weights':tf.Variable(tf.random_normal([400,n_nodes_hl1])),
'biases':tf.Variable(tf.random_normal(n_nodes_hl1))}
hidden_layer2 = {'weights':tf.Variable(tf.random_normal([n_nodes_hl1,n_nodes_hl2])),
'biases':tf.Variable(tf.random_normal(n_nodes_hl2))}
hidden_layer3 = {'weights':tf.Variable(tf.random_normal([n_nodes_hl2,n_nodes_hl3])),
'biases':tf.Variable(tf.random_normal(n_nodes_hl3))}
output_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl3,n_classes])),
'biases':tf.Variable(tf.random_normal([n_classes]))}
#(input * weights) + biases
l1 = tf.add(tf.matmul(data, hidden_layer1['weights']),hidden_layer1['biases'])
l1 = tf.nn.relu(l1)
l2 = tf.add(tf.matmul(l1, hidden_layer2['weights']),hidden_layer2['biases'])
l2 = tf.nn.relu(l2)
l3 = tf.add(tf.matmul(l2, hidden_layer3['weights']),hidden_layer3['biases'])
l3 = tf.nn.relu(l3)
output = tf.add(tf.matmul(l3, output_layer['weights']),output_layer['biases'])
return output
高清train_neural_network(X):
prediction = neural_network_model(x)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction,y))
optimizer = tf.train.AdamOptimizer().minimize(cost)
hm_epochs = 4999
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
for epoch in range(hm_epochs):
sess.run([optimizer,cost], feed_dict = {x: input_X[epoch], y: encoded_y[epoch]})
print('Epoch',epoch,'completed out of', hm_epochs)
實際的錯誤是這樣的:
%運行「/ US ERS/JaeWoo /桌面/研究/ tensorpractice/DeepNeural.py」
train_neural_network(X)
W¯¯tensorflow /核心/框架/ op_kernel.cc:940]參數無效:形狀必須{INT32的矢量,int64},got shape []
W tensorflow/core/framework/op_kernel.cc:940]無效參數:shape必須是{int32,int64}的向量,得到shape [] ...重複for幾次
InvalidArgumentError回溯(最近的最後一次呼叫)
在()
----> 1個train_neural_network(x)的
/Users/JaeWoo/Desktop/research/tensorpractice/DeepNeural.py在
train_neural_network(X)
67
68 with tf.Session() as sess:
---> 69 sess.run(tf.initialize_all_variables()) 71在範圍曆元(hm_epochs):
到底是什麼你得到的錯誤?你可以將它添加到你的問題或作爲評論? – Steven
你能改變這個「feed_dict = {」爲「feed_dict = {」。我不記得間距是否重要。 – Steven
我添加了錯誤。謝謝! – Djae