我想对包含的信号进行分类

X = (n_samples, n_timesteps, n_features) ,其中 n_samples=476n_timesteps=400n_features=16 是信号的采样数,时间步长和特征(或通道) .

y = (n_samples, n_timesteps, 1) . 每个时间步长标记为0或1(二进制分类) .

我的图模型如下图所示 .

enter image description here

输入馈入32单元LSTM . LSTM输出进入1单位密集层以生成400x1向量,其中400是时间步数 . 然后我想将这个400x1矢量放入一个400单位的Dense层 . 我试图压平1单位密集,但最终输出的形状与标签400x1向量不匹配 .

摘录和模型如下所示 .

input_layer = Input(shape=(n_timestep, n_feature))
lstm1 = LSTM(32, return_sequences=True)(input_layer)
dense1 = Dense(1, activation='sigmoid')(lstm1)
flat1 = TimeDistributed(Flatten())(dense1)        
dense2 = TimeDistributed(Dense(400, activation='sigmoid'))(flat1)
model = Model(inputs=input_layer, outputs=dense2)
model.summary()

enter image description here

错误如下所示 .

ValueError: Error when checking target: expected time_distributed_4 to have shape (400, 400) but got array with shape (400, 1)

请让我知道如何解决它 . 谢谢 .