【发布时间】:2019-08-07 01:51:50
【问题描述】:
无法为我的模型找到确切的输入形状,它具有 (35,33297) 形状
我已经用 np.expand dims 试过了,但它也不起作用
model=Sequential()
model.add(LSTM(50,return_sequences=True, input_shape=(X_train.shape)))
model.add(LSTM(32, return_sequences=True ))
model.add(Dense(2, activation='softmax'))
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])```
```print("Train...")
model.fit(X_train,y_train,batch_size=5,epochs=10,verbose=1)```
```Train...
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-123-a64af5eee5e8> in <module>()
1 print("Train...")
----> 2 model.fit(X_train,y_train,batch_size=5,epochs=10,verbose=1)
~\Anaconda3\lib\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, steps_per_epoch, validation_steps, **kwargs)
950 sample_weight=sample_weight,
951 class_weight=class_weight,
--> 952 batch_size=batch_size)
953 # Prepare validation data.
954 do_validation = False
ValueError: Error when checking input: expected lstm_37_input to have 3 dimensions, but got array with shape (35, 33297)```
【问题讨论】:
-
你给了 LSTM 一个大小为
(35, 33297)的数组。但是 LSTM 需要一个[batch_size, seq length, num features]数组。你在使用np.expand_dims时遇到了什么错误? -
我在执行时确实遇到了任何错误
-
但如果我使用的是批量大小,则表明 dim 大于 3
标签: tensorflow keras deep-learning lstm