使用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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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