3
我在Keras的LSTM上遇到了一些麻煩。我已經重塑了一些數據(NUM_ROWS,num_timesteps,num_dimensions),但我得到一個錯誤,當我嘗試適合說難以置信的類型:'尺寸'在Keras LSTM
TypeErrorTraceback (most recent call last)
<ipython-input-61-a1844d288e79> in <module>()
10 print("Actual input: {}".format(X.shape))
11 print("Actual output: {}".format(Y.shape))
---> 12 history = model.fit(X, Y, epochs=2, batch_size=100, verbose=1)
/opt/conda/lib/python3.6/site-packages/keras/models.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, **kwargs)
843 class_weight=class_weight,
844 sample_weight=sample_weight,
--> 845 initial_epoch=initial_epoch)
846
847 def evaluate(self, x, y, batch_size=32, verbose=1,
/opt/conda/lib/python3.6/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, **kwargs)
1403 class_weight=class_weight,
1404 check_batch_axis=False,
-> 1405 batch_size=batch_size)
1406 # prepare validation data
1407 if validation_data:
/opt/conda/lib/python3.6/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_batch_axis, batch_size)
1305 for (ref, sw, cw, mode)
1306 in zip(y, sample_weights, class_weights, self._feed_sample_weight_modes)]
-> 1307 _check_array_lengths(x, y, sample_weights)
1308 _check_loss_and_target_compatibility(y,
1309 self._feed_loss_fns,
/opt/conda/lib/python3.6/site-packages/keras/engine/training.py in _check_array_lengths(inputs, targets, weights)
208 y_lengths = [y.shape[0] for y in targets]
209 w_lengths = [w.shape[0] for w in weights]
--> 210 set_x = set(x_lengths)
211 if len(set_x) > 1:
212 raise ValueError('All input arrays (x) should have '
TypeError: unhashable type: 'Dimension'
我的代碼,所有的進口之後,並在數據讀取,是
X = reshape(np.array(dat), [10000, 101, 26])
model = Sequential()
model.add(LSTM(1, input_shape=(101, 26), return_sequences=False))
model.compile(loss='binary_crossentropy',
optimizer= 'adam',
metrics=['binary_accuracy'])
model.summary()
print("Inputs: {}".format(model.input_shape))
print("Outputs: {}".format(model.output_shape))
print("Actual input: {}".format(X.shape))
print("Actual output: {}".format(Y.shape))
history = model.fit(X, Y, epochs=2, batch_size=100, verbose=1)
和完整性檢查行給出:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_19 (LSTM) (None, 1) 112
=================================================================
Total params: 112.0
Trainable params: 112
Non-trainable params: 0.0
_________________________________________________________________
Inputs: (None, 101, 26)
Outputs: (None, 1)
Actual input: (10000, 101, 26)
Actual output: (10000, 1)
我在做什麼錯?
在堆棧跟蹤中添加更多上下文。代碼中的哪一行導致拋出的錯誤 – putonspectacles
添加了完整的堆棧跟蹤。 –