检查目标时发生错误:预期density_1具有2维,但数组的形状为(1,4000,25)

问题描述 投票:0回答:2

我正在尝试训练LSTM网络以进行无监督的二进制分类。

我有一个整数矩阵作为输入,每一行都是一个不同的跟踪广告,每一列都是一个特征。

这是我使用的模型:

time_steps = 4000
features = 25
model = Sequential()
model.add(LSTM(128, input_shape=(time_steps, features), name='lstm'))
model.add(Dense(1, activation='relu'))
model.summary()
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(x_train, x_train, batch_size=batch_size, epochs=epochs, verbose=2)

这是我得到的错误:

检查目标时发生错误:预期density_1具有2维,但数组的形状为(1,4000,25)

它在尝试运行model.fit时生成”

输入的格式如下:

x_train = np.array([input_array[:4000]])

输入的每条迹线都有25个特征。

我是该领域的新手,我不知道该如何解决问题。我已经检查过类似的票,但没有一个能帮助我。

这里有一些我分析过的票:

Error when checking target: expected dense_1 to have 3 dimensions, but got array with shape (118, 1)

ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (68, 50, 50, 50, 1)

Error when checking target: expected dense_2 to have 2 dimensions, but got array with shape (1, 1226, 2)

ValueError: Error when checking target: expected dense_2 to have 3 dimensions, but got array with shape (10000, 1)

我正在尝试训练LSTM网络进行无监督的二进制分类。我有一个整数矩阵作为输入,每一行都是一个不同的跟踪广告,每一列都是一个特征。这是模型...

tensorflow keras classification lstm unsupervised-learning
2个回答
1
投票

几句话:


0
投票

您尚未显示input_array的形状,但是您可以尝试使用np.reshape(input_array, (4000, 25))对其进行重塑。阅读更多有关重塑here

© www.soinside.com 2019 - 2024. All rights reserved.