python - ValueError: Input 0 is incompatible with layer repeat_vector_58: expected ndim=2, found ndim=3
问题描述
I am trying to build intrusion detection LSTM and auto encoders. However I am not able to understand why repeat_vector_58 requires ndim=3. I am not able to figure this out. Below is my code:
x_train.shape: (8000, 1, 82)
x_test.shape: (2000, 1, 82)
x_train = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))
x_test = np.reshape(testT, (testT.shape[0], 1, testT.shape[1]))
start = time.time()
model = Sequential()
model.add(LSTM(128, activation='relu',recurrent_dropout=0.5,return_sequences=True,input_dim=82))
model.add(RepeatVector(82))
model.add(Dropout(0.3))
model.add(LSTM(64, activation='relu',recurrent_dropout=0.5,return_sequences=False))
model.add(Dropout(0.3))
model.add(TimeDistributed(Dense(1,activation='softmax')))
ValueError: Input 0 is incompatible with layer repeat_vector_58: expected ndim=2, found ndim=3
解决方案
LSTM 层需要 3 维输入,因为它是循环层。预期的输入是(batch_size, timesteps, input_dim)
。规范input_dim=82
需要 2-dim 输入,但预期输入是 3-dim。
因此,您的错误的解决方案是更改input_dim=82
为input_shape=(82,1)
.
model = Sequential()
model.add(LSTM(128,activation='relu',recurrent_dropout=0.5,return_sequences=True,input_shape=(82,1)))
推荐阅读
- javascript - js中没有定义的函数
- node.js - 基于用户位置的每日更新
- format - 您能否格式化图例,以便每个值在 Tableau 中显示两种颜色?
- c++ - 在保持排序的同时在单链表中插入新节点
- javascript - 当索引满足另一个条件时,查找 Javascript 数组元素的值和索引
- redux - 静态页面数据 - Redux 还是 Vanilla JS?
- javascript - 替换php元素(图像和名称),在js中点击
- html - 如何将 Div 与英雄图像重叠以实现 Material-Design 外观?
- netbeans - 将 Netbeans Projects 文件夹移动到云
- excel - 如果在另一列中更改了多个单元格,则更新一列中的多个单元格