我在尝试重写一个用于分类卫星图像的神经网络模型,我想在这个模型中加入一些卷积层,比如 #keras.layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu', padding = 'same',input_shape=(1,nBands)),
但是我无法正确设置input_shape
参数,有人能帮我吗?
之前的神经网络模型是这样的:
# Print the shape of reshaped dataprint(xTrain.shape, xTest.shape, featuresHyderabad.shape)#(2519025, 1, 6) (1679351, 1, 6) (1391808, 1, 6)# Define the parameters of the modelmodel = keras.Sequential([ #keras.layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu', padding = 'same',input_shape=(1,nBands)), keras.layers.Flatten(input_shape=(1, nBands)), keras.layers.Dense(128, activation='relu',kernel_initializer='glorot_normal'), keras.layers.Dense(2, activation='softmax')])# Define the accuracy metrics and parametersmodel.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])# Run the modelmodel.fit(xTrain, yTrain, epochs=2,batch_size=10)
回答:
输入形状必须是图像的形状。例如,如果你用48×48的黑白图像训练模型,输入形状将是(48,48,1),或者如果通道值放在高度和宽度之前,则为(1,48,48)。