我無法解決我的代碼問題。我不斷收到以下錯誤信息,當我運行我的代碼:重塑錯誤張量流RNN
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-cdb1929785d0> in <module>()
108 tf.reset_default_graph()
109
--> 110 train_neural_network(x)
<ipython-input-1-cdb1929785d0> in train_neural_network(x)
93 end = i+batch_size
94 batch_x = np.array(X_train[start:end])
---> 95 batch_x = batch_x.reshape((batch_size,n_chunks,chunk_size))
96 batch_y = np.array(y_1Hot_train.eval()[start:end])
97
ValueError: cannot reshape array of size 784 into shape (10,28,28)
我的數據集爲(88041,784)陣列,其中我具有爲10的批量大小當我走線95和運行它獨立我沒有得到任何錯誤,重塑發生沒有失敗。
例如,除了張量流,這段代碼段的工作原理:
batch_x = np.array(X_train[0:10])
batch_x = batch_x.reshape((batch_size,n_chunks,chunk_size))
batch_x.shape # returns a shape of (10, 28, 28)
所以我不確定爲什麼張量流不斷拋出錯誤。如果你有更好的主意,我會非常感激。
的tf.sessions部分是:
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for epoch in range (hm_epochs):
epoch_loss = 0
itere = int(X_train.shape[0]/batch_size)
last = 0
add = 1
batch_size = 10
i=0
while i < len(X_train):
start = i
end = i+batch_size
batch_x = np.array(X_train[start:end])
batch_x = batch_x.reshape((batch_size,n_chunks,chunk_size))
batch_y = np.array(y_1Hot_train.eval()[start:end])
_, c = sess.run([optimizer, cost], feed_dict={x: batch_x,
y: batch_y})
epoch_loss += c
i+=batch_size
sess_end = time.time() - start_time
的代碼是在這裏:https://gist.github.com/makark/bab1cd6a80667226d0aff35f637463b0
'(10,28,28)'是7840,比784高一個數量級。你也使用了批量大小10.完全刺在黑暗中(因爲我不知道你在做什麼):'batch_x = batch_x.reshape((1,n_chunks,chunk_size))' – roganjosh