Keras 什么是致密层?

Keras 什么是致密层?,keras,deep-learning,lstm,Keras,Deep Learning,Lstm,我在使用LSTM训练数据集时遇到问题,原因是: Error when checking target: expected dense_2 to have shape (, 1) but got array with shape (, 0) 在尝试之后,我将密度层单位改为1到0,解决了我的问题。 这个密集层的作用是什么?将其更改为0后会发生什么 重塑数据集 x_train = np.reshape(x_train, (x_train.shape[0],x_train.shape[1],1))

我在使用LSTM训练数据集时遇到问题,原因是:

 Error when checking target: expected dense_2 to have shape (, 1) but got array with shape (, 0)
在尝试之后,我将密度层单位改为1到0,解决了我的问题。 这个密集层的作用是什么?将其更改为0后会发生什么

重塑数据集

x_train = np.reshape(x_train, (x_train.shape[0],x_train.shape[1],1))
模型:

regressor = Sequential()

#1
regressor.add(LSTM(units = 50, return_sequences = True , input_shape = (x_train.shape[1],1)))
regressor.add(Dropout(0.2))
#2
regressor.add(LSTM(units = 50, return_sequences = True))
regressor.add(Dropout(0.2))
#3
regressor.add(LSTM(units = 50, return_sequences = True))
regressor.add(Dropout(0.2))
#4
regressor.add(LSTM(units = 50))
regressor.add(Dropout(0.2))

regressor.add(Dense(units = 0))

regressor.compile(optimizer = 'adam' , loss = 'mean_squared_error')

regressor.fit(x_train, y_train, epochs = 100, batch_size = 32)

我完全不熟悉机器学习

密集层是一个层,其中每个输入神经元连接到输出神经元,就像一个简单的神经网络,参数单位只告诉你输出的维度

我认为您的问题来自输入数据的维度, 你能打印出你的输入数据吗,
它应该是4D

请显示模型的其余部分,最好是代码的其余部分。您需要在第四个
退出
层后添加一个
flatte()
层。此外,单位为0的密集层不会处理任何数据,因为输出维度变为0。