我正在尝试在具有 3100 个特征和 53953 行的数值数据集上运行卷积自动编码器。所以在编码器层,当我传递输入时,我得到ValueError: Input 0 is incompatible with layer conv2d_44: expected ndim=4, found ndim=2的错误。我找到了很多关于图像数据的解释。但是,找不到对数值数据集的任何解释。我的代码如下:
from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D
from keras.models import Model
from keras.layers import *
inputTensor = Input(shape=(3100,))
x = Conv2D(32, (3, 3), activation='relu', padding='same')(inputTensor)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(32, (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
autoencoder = Model(inputTensor, decoded)
autoencoder.compile(optimizer='adadelta', loss='mean_squared_error')
autoencoder.fit(X, X, epochs=5, batch_size=1032)
有人可以解释一下我在这里遗漏了什么吗?或者如何在卷积层中传递数值数据?