使用Keras和TensorFlow将神经网络模型修改为卷积神经网络

我在尝试重写一个用于分类卫星图像的神经网络模型,我想在这个模型中加入一些卷积层,比如 #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)。

Related Posts

理解torch.nn.Flatten

我理解Flatten会移除除了一个维度之外的所有维度。…

SGD分类器的精确度-召回率曲线

我正在处理一个二分类问题,并使用了一个如下所示的SGD…

Pytorch张量的最小值和最大值

已关闭。 此问题无法重现或由拼写错误引起。目前不接受回…

python plotly fill between range

我在尝试使用Python的Plotly绘制学习曲线。 …

CNN Pytorch 仅支持空间目标批处理错误

我已经设计了以下模型,用于对MNIST时尚数据进行分类…

如何在sklearn逻辑回归中使用tanh替代sigmoid

是否有方法可以使用tanh运行sklearn的逻辑回归…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注