我第一次为图像分类构建 CNN 模型,我对每种类型(1D CNN、2D CNN、3D CNN)的输入形状以及如何修复过滤器的数量有点困惑卷积层。我的数据是 100x100x30,其中 30 个是特征。这是我使用功能 API Keras 为 1D CNN 编写的文章:
def create_CNN1D_model(pool_type='max',conv_activation='relu'):
input_layer = (30,1)
conv_layer1 = Conv1D(filters=16, kernel_size=3, activation=conv_activation)(input_layer)
max_pooling_layer1 = MaxPooling1D(pool_size=2)(conv_layer1)
conv_layer2 = Conv1D(filters=32, kernel_size=3, activation=conv_activation)(max_pooling_layer1)
max_pooling_layer2 = MaxPooling1D(pool_size=2)(conv_layer2)
flatten_layer = Flatten()(max_pooling_layer2)
dense_layer = Dense(units=64, activation='relu')(flatten_layer)
output_layer = Dense(units=10, activation='softmax')(dense_layer)
CNN_model = Model(inputs=input_layer, outputs=output_layer)
return CNN_model
CNN1D = create_CNN1D_model()
CNN1D.compile(loss = 'categorical_crossentropy', optimizer = "adam",metrics = ['accuracy'])
Trace = CNN1D.fit(X, y, epochs=50, batch_size=100)
但是,在尝试通过将 Conv1D、Maxpooling1D 更改为 Conv2D 和 Maxpooling2D 来尝试 2D CNN 模型时,出现以下错误:
ValueError: Input 0 of layer conv2d_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 30, 1)
谁能告诉我 2D CNN 和 3D CNN 的输入形状如何?输入数据预处理可以做什么?