恢复通过Keras平铺层后的多波段图像形状

我有一张包含6个不同波段的图像。

我已经对图像进行了预处理,以便为模型做好准备,如下所示:

ds1, image = raster.read(imagePath, bands='all')

然后我使用pyrsgis重塑了图像

image = changeDimension(image)

最后,我将其除以255

xTrain = xTrain / 255.0

并重新塑形以与手动标记的类别匹配

image= image.reshape((image.shape[0], 1, image.shape[1]))

我试图将图像通过我用Keras构建的自编码器,该自编码器具有以下结构:

model = keras.Sequential([    keras.layers.Flatten(input_shape=(1, nBands)),    keras.layers.Dense(14, activation='relu'),    keras.layers.Dense(2, activation='relu', activity_regularizer=l1(10e-6)),    keras.layers.Dense(14, activation='relu'),    keras.layers.Dense(6, activation='sigmoid')])

训练效果很好。当我使用 predicted = model.predict(newImg) 时,我得到了形状为 (1391808, 6) 的预测数组。

但问题是,我不知道如何从输出中重建图像,以便最终保存它。


回答:

如果有人遇到相同的问题,这是解决方案

predicted = model.predict(featuresHyderabad)predictedArr = np.zeros(shape = ( nBands, imageHeight, imageWidth ))for i in range(nBands):  prediction = np.reshape(predicted[:,i], (imageHeight, imageWidth))  predictedArr[i] = predictionraster.export(predictedArr, metaData, filename=outFile, dtype='float', bands='all')

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中创建了一个多类分类项目。该项目可以对…

发表回复

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