毕设 基于U-Net网络的遥感图像语义分割(源码+论文)


0 项目说明

**基于 U-Net 网络的遥感图像语义分割 **

提示:适合用于课程设计或毕业设计,工作量达标,源码开放

实验训练使用 Anaconda 版 Python 3.7 下的 TensorFlow-GPU1.8
后期图像生成由于 GPU 显存限制,使用 TensorFlow 的 CPU 版本进行计算预测图计算。


1 研究目的

U-Net 是一种由全卷积神经网络启发的对称结构网络,在医疗影像分割领域取得了很好的效果。 此次研究尝试使用 U-Net 网络在对多光谱遥感影像数据集上进行训练,尝试使用卷积神经网络自动分割出建筑,希望能够得到一种自动分割遥感影像的简便方法。

2 研究方法

首先提出了一种基于遥感图像类别比率的交叉熵损失函数——类别平衡交叉熵。并与应用于医疗图像分割的 U-Net 相结合,将其应用于遥感图像语义分割。

在 Inria Aerial Image Labeling Dataset 训练数据集上分别使用交叉熵损失函数和类别平衡交叉熵损失函数进行训练,得到两个训练好的卷积神经网络。再利用这两个网络在 Inria Aerial Image Labeling Dataset 测试数据集上生成预测图像进行比对。

3 研究结论

两种方法在正确率和交叉熵上没有太大差别,以交叉熵作为损失函数略优于以类别平衡交叉熵方法。但是这两种方法在F1 Score 上有较大差别。交叉熵的 F1 Score 为 0.47,类别平衡交叉熵的F1 Score 为 0.51,类别平衡交叉熵较交叉熵提高了 8.5%。
在这里插入图片描述

4 论文目录

第一章 绪论
1.1 研究背景与意义
1.2 国内外研究现状
1.2.1 语义分割研究现状
1.2.2 将深度学习应用于遥感图像分割现状
1.3 本文的主要工作
1.4 论文章节安排
第二章 背景知识
2.1 全卷积网络
2.2 使用全连接网络进行精准分割
2.2.1 线性结构网络
2.2.2 对称结构网络
第三章 实验设计
3.1 数据集选择及处理
3.2 图像处理流程设计
3.2.1 网络结构
3.2.2 卷积核初始化方案
3.2.3 输出图像恢复及优化
3.3 损失设计
3.3.1 交叉熵
3.3.2 带权重的交叉熵
3.3.3 类别平衡交叉熵
3.4 结果评估
3.5 具体实现
3.5.1 实验平台
3.5.2 模型实现
第四章 实验
4.1 网络初始化设计
4.2 实验结果
4.2.1 第一组:交叉熵
4.2.2 第二组:类别平衡交叉熵
4.2.3 结果分析
4.3 典型错误
4.3.1 建筑过大
4.3.2 错认
4.3.3 树木和光影
4.4 最终结果
第五章 总结和展望
5.1 全文总结
5.2 未来展望
致谢
参考文献

5 项目源码

from glob import glob
from PIL import Image
from os import path, makedirs
import numpy as np
from itertools import count, cycle
import logging

logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')

color_class_dict = {(0,): 1, (255,): 0}
n_class = len(list(color_class_dict.keys()))


def name_generator(file_path, ex_name=None, cycle_num=None):
    if len(file_path.split('.')) == 2:  # file_path带扩展名
        true_file_name = path.basename(file_path).split('.')[-2]
        true_file_type = path.basename(file_path).split('.')[-1]
    else:  # file_path不带拓展名
        true_file_name = path.basename(file_path)
        true_file_type = None
    if not ex_name:
        true_file_type = None
    elif ex_name is not None:
        true_file_type = ex_name
    if cycle_num is not None:
        for i in cycle(range(cycle_num)):
            if true_file_type is not None:
                yield true_file_name + '_' + str(i) + '.' + true_file_type
            else:
                yield true_file_name + '_' + str(i)
    else:
        for i in count(0):
            if true_file_type is not None:
                yield true_file_name + '_' + str(i) + '.' + true_file_type
            else:
                yield true_file_name + '_' + str(i)


def resize_image(image_path, new_width, new_height, save_dir=None):
    image = Image.open(image_path)
    image = image.resize((new_width, new_height))
    if save_dir is not None:
        file_name = path.basename(image_path)
        image.save(path.join(save_dir, file_name))
    else:
        image.save(image_path)


def split_image(image_path,
                split_width,
                split_height,
                save_dir,
                save_as_img=False):
    # 按下面顺序分割:
    # 1 2 3
    # 4 5 6
    image = Image.open(image_path)
    image_width, image_height = image.size
    if image_width % split_width or image_height % split_height:
        raise ValueError('该图像大小为:{}x{};不能被等分为{}x{}的图像'.format(
            image_width, image_height, split_width, split_height))
    new_name = name_generator(image_path, ex_name=False)
    for i in range(0, image_height, split_height):
        for j in range(0, image_width, split_width):
            cutting_box = (j, i, j + split_width, i + split_height)
            slice_of_image = image.crop(cutting_box)
            if save_as_img:
                slice_of_image.save(
                    path.join(save_dir,
                              next(new_name) + '.png'))
            else:
                slice_of_image = np.array(slice_of_image)
                np.save(path.join(save_dir, next(new_name)), slice_of_image)


def glut_image(image_list, glut_cols, glut_rows, image_width, image_height,
               save_path):
    glutted_image = Image.new(
        'RGB', (image_width * glut_cols, image_height * glut_rows))
    k = 0
    for i in range(glut_rows):
        for j in range(glut_cols):
            # 判断image_list是不是字符串
            # paste_it = Image.open(image_list[k])
            paste_it = image_list[k]
            glutted_image.paste(paste_it, (j * image_width, i * image_height))
            k += 1
    glutted_image.save(save_path)


def color_to_class(image_path, save_path=None):
    raw_image = np.load(image_path)
    raw_image = np.reshape(raw_image,
                           (raw_image.shape[0], raw_image.shape[1], -1))
    [rows, cols, _] = raw_image.shape
    classed_image = np.zeros((rows, cols, n_class))
    for i in range(rows):
        for j in range(cols):
            classed_image[i, j, color_class_dict[tuple(raw_image[i, j])]] = 1
    if save_path is not None:
        np.save(path.join(save_path,
                          path.basename(image_path).split('.')[-2]),
                classed_image)
    else:
        return classed_image


def output_map_to_class(output_map):
    most_possible_label = np.argmax(output_map, 2)
    classed_image = np.zeros(shape=output_map.shape)
    [rows, cols] = most_possible_label.shape
    for i in range(rows):
        for j in range(cols):
            classed_image[i, j, most_possible_label[i, j]] = 1
    return classed_image


def class_to_color(classed_image):
    reverse_color_class_dict = dict(
        zip(color_class_dict.values(), color_class_dict.keys()))
    colored_image = np.zeros(shape=(classed_image.shape[0],
                                    classed_image.shape[1],
                                    len(list(color_class_dict.keys())[0])))
    for i in range(classed_image.shape[0]):
        for j in range(classed_image.shape[1]):
            for k in range(n_class):
                if classed_image[i][j][k] == 1:
                    colored_image[i][j] = reverse_color_class_dict[k]
    return colored_image

6 最后

**项目分享: ** https://gitee.com/asoonis/htw

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 基于 U-Net 网络遥感图像语义分割是一种用于识别遥感图像中不同类别区域的方法。U-Net 是一种用于图像分割任务的深度学习网络,通过将高分辨率的图像输入网络,并逐步降低分辨率再进行上采样,从而实现对图像的全局和局部特征的建模。 在遥感图像语义分割中,首先将训练样本标注为不同的类别,例如建筑物、道路、水体等。然后,利用 U-Net 网络进行训练,通过学习训练样本的特征来建立起不同类别之间的关联。此外,U-Net 网络还通过跳跃连接(skip connection)实现了底层和高层特征的融合,提高了图像分割的准确性。 在进行遥感图像语义分割时,首先将输入的遥感图像经过预处理,如归一化处理和裁剪等,然后输入 U-Net 网络中进行特征提取和分割。通过网络的卷积和池化操作,可以获取到图像的局部和全局特征。然后,通过上采样操作和跳跃连接的融合,获得高分辨率的分割结果。 基于 U-Net 网络遥感图像语义分割具有以下优点:首先,U-Net 网络能够学习不同类别之间的关联和特征表示,从而能够准确地分割出遥感图像中的不同类别。其次,通过跳跃连接的融合,U-Net 网络能够捕捉到不同层次的特征,提高了分割结果的准确性和完整性。最后,U-Net 网络具有较好的扩展性和泛化能力,可以应用于不同尺度和不同类别的遥感图像分割任务。 总之,基于 U-Net 网络遥感图像语义分割是一种高效准确的遥感图像处理方法,具有广阔的应用前景。 ### 回答2: 遥感图像语义分割是指对遥感图像中的每个像素进行分类,将其分为不同的语义类别。基于U-Net网络遥感图像语义分割是一种常用的深度学习方法。 U-Net是由Ronneberger等人在2015年提出的一种图像分割网络。它的结构包含两个部分:下采样路径和上采样路径。下采样路径通过卷积层和池化层逐步减小图像的大小,提取图像的全局和局部特征。上采样路径使用反卷积层和跳跃连接将特征图恢复到原始输入图像的大小,并通过逐步合并特征图,进行语义分割的预测。 基于U-Net网络遥感图像语义分割的步骤如下: 1. 数据准备:收集遥感图像数据集,并将其标注为不同的语义类别。 2. 数据预处理:对图像进行预处理,包括图像增强、归一化等操作,以提高网络的学习效果。 3. 搭建U-Net网络:根据U-Net的结构搭建网络模型,定义损失函数以及优化器。 4. 模型训练:使用训练集对网络进行训练,通过最小化损失函数来优化网络的参数。 5. 模型评估:使用验证集对网络进行评估,计算指标如准确率、召回率、F1值等,判断模型的性能。 6. 模型应用:使用训练好的模型对新的遥感图像进行语义分割,将每个像素分配到相应的语义类别中。 基于U-Net网络遥感图像语义分割方法具有以下优点:能够利用图像的全局和局部特征进行分割,同时通过跳跃连接可以更好地保留图像中的细节信息,提高分割精度。但仍需根据实际情况选择合适的网络结构和参数,以获取更好的分割效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值