如何在水体分割中获得更好的效果?

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

这是我的第一个计算机视觉项目,我仍在了解基础知识。我正在使用 Kaggle 的水分割数据集,并尝试使用 1888 个图像训练模型。我想执行语义分割来分割图像中的水部分。我使用的模型是U-net架构。该模型在测试图像上表现良好,并且我得到了一些不错的结果,但是当我尝试对新图像进行预测时,结果非常糟糕。我尝试了不同的预训练模型,但它们的表现更差。模型架构如下代码,下面还附有输出图像。有谁知道更好的方法或者我在这里做错了什么?

from keras.models import Model
from keras.layers import Input, Conv2D, MaxPooling2D, UpSampling2D, concatenate, Conv2DTranspose, BatchNormalization, Dropout, Lambda
from tensorflow.keras.optimizers import Adam
from keras.layers import Activation, MaxPool2D, Concatenate


def conv_block(input, num_filters):
    x = Conv2D(num_filters, 3, padding="same")(input)
    x = BatchNormalization()(x)    
    x = Activation("relu")(x)

    x = Conv2D(num_filters, 3, padding="same")(x)
    x = BatchNormalization()(x)  #Not in the original network
    x = Activation("relu")(x)

    return x


def encoder_block(input, num_filters):
    x = conv_block(input, num_filters)
    p = MaxPool2D((2, 2))(x)
    return x, p   


def decoder_block(input, skip_features, num_filters):
    x = Conv2DTranspose(num_filters, (2, 2), strides=2, padding="same")(input)
    x = Concatenate()([x, skip_features])
    x = conv_block(x, num_filters)
    return x


def build_unet(input_shape, n_classes):
    inputs = Input(input_shape)

    s1, p1 = encoder_block(inputs, 64)
    s2, p2 = encoder_block(p1, 128)
    s3, p3 = encoder_block(p2, 256)
    s4, p4 = encoder_block(p3, 512)

    b1 = conv_block(p4, 1024) #Bridge

    d1 = decoder_block(b1, s4, 512)
    d2 = decoder_block(d1, s3, 256)
    d3 = decoder_block(d2, s2, 128)
    d4 = decoder_block(d3, s1, 64)

    if n_classes == 1:  #Binary
      activation = 'sigmoid'
    else:
      activation = 'softmax'

    outputs = Conv2D(n_classes, 1, padding="same", activation=activation)(d4)  #Change the activation based on n_classes
    print(activation)

    model = Model(inputs, outputs, name="U-Net")
    return model
model = build_unet(input_shape, n_classes=1)
model.compile(optimizer=Adam(learning_rate = 1e-3), loss='binary_crossentropy', metrics=['accuracy'])
model.summary()

这是测试数据的结果:
enter image description here

这是新图像的结果:
enter image description here`

python deep-learning computer-vision image-segmentation semantic-segmentation
2个回答
0
投票

我的猜测是,您对测试数据进行了一些预处理,而这些预处理并未对新图像执行。具体来说,我会研究图像归一化:在大多数图像处理神经网络中,输入图像被归一化为(大致)零均值和单位方差。如果这种归一化是您的训练/评估代码的一部分,则在由经过训练的 U-net 处理新图像之前,您也必须对新图像进行相同的归一化。


0
投票

请参阅以下论文,Lufi-RiverSnap 数据集和代码是免费提供的: https://ieeexplore.ieee.org/abstract/document/10493013

A. Moghimi、M. Welzel、T. Celik 和 T. Schlurmann,“近距离遥感图像河水分割的流行深度学习模型和分段任意模型 (SAM) 的性能比较分析”,IEEE Access,doi: 10.1109/访问.2024.3385425.

他们针对水分割对 SAM 进行了微调,结果非常有用,并且还有改进代码的方法。

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