gpt4 book ai didi

tensorflow - keras 一维卷积输入形状

转载 作者:行者123 更新时间:2023-12-04 19:29:40 25 4
gpt4 key购买 nike

我正在尝试为 1D 卷积创建模型,但我似乎无法获得正确的输入形状。这是我所拥有的:

#this is actually shape (6826, 9000) but I am shortening it
train_dataset_x = np.array([[0, 1, 5, 1, 10], [0, 2, 4, 1, 3]])
#this is actually shape (6826, 1)
train_dataset_y = np.array([[0], [1]])

model.add(Conv1D(32, 11, padding='valid', activation='relu', strides=1, input_shape=( len(train_dataset_x[0]), train_dataset_x.shape[1]) ))
model.add(Conv1D(32, 3, padding='valid', activation='relu', strides=1) )
model.add(MaxPooling1D())

model.add(Conv1D(64, 3, padding='valid', activation='relu', strides=1) )
model.add(Conv1D(64, 3, padding='valid', activation='relu', strides=1) )
model.add(MaxPooling1D())


model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

我收到此错误:
ValueError: Error when checking input: expected conv1d_1_input to have 3 dimensions, but got array with shape (6826, 9000)

有人有建议吗?

最佳答案

输入到 keras.layers.Conv1D应该是 3-d 尺寸 (nb_of_examples, timesteps, features) .我假设您有一个长度为 6000 的序列具有 1 个功能。在这种情况下:

X = X.reshape((-1, 9000, 1))

应该做这项工作。

关于tensorflow - keras 一维卷积输入形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45471004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com