如何正确保存使用 Rastervision 做出的预测?

问题描述 投票:0回答:1

我能够使用 Rastervision (RV) 作为模块来制作我的第一个完整的语义分割管道。我用这个 dataset 在这个 Kaggle notebook 上编写了代码。

对于验证数据集来说,预测是可以的(考虑到使用的操作系统纪元数),但是当我使用我的学习器为我的预测数据集生成预测时:

from rastervision.core.data import SemanticSegmentationLabels

predictions = learner.predict_dataset(
    dataset=prediction_dataset,
    raw_out=True,
    numpy_out=True,
    predict_kw=dict(out_shape=IMG_SIZE), # using 256x256
    progress_bar=True,
)

pred_labels = SemanticSegmentationLabels.from_predictions(
    windows=prediction_dataset.windows,
    predictions=predictions,
    smooth=True, # trying both outputs
    extent=prediction_dataset.scene.extent,
    num_classes=len(class_config),
)

结果并不好。我做错了什么?

以下是我的验证数据集的预测:

这是保存的 geotif 文件:

pred_labels.save(
    uri=os.path.join(OUTPUT_DIR, 'predictions'),
    crs_transformer=prediction_dataset.scene.raster_source.crs_transformer,
    class_config=class_config,
)

在左侧,我们显示了窗口的标签,在右侧,我们在保存的 geotiff 上保存了相同的窗口。

这里可能出现什么问题?

python deep-learning geospatial semantic-segmentation
1个回答
0
投票

我从 Azavea 的 GitHub 这里的官方讨论中获得了帮助。

问题是我没有在预测模式下加载我的学习器。我需要做:

bundle_uri = os.path.join(OUTPUT_DIR, 'model-bundle.zip')
predictlearner = SemanticSegmentationLearner.from_model_bundle(
    model_bundle_uri=bundle_uri,
    training=False,
    output_dir=OUTPUT_DIR,
)

在预测之前执行此操作可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.