本项目借助PaddleSeg模块训练Transformer类的Segformer_b3语义分割模型,为航空遥感图像特征点匹配提供语义约束以提升三维重建精度。使用UDD6数据集,经裁剪处理后训练,40000次迭代耗时12小时,mIOU达74.50%,较原论文DeepLabV3+高1.32%。模型可对指定图像预测,结果存于指定文件夹,能助力提升SfM三维重建精度与速度。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

SfM(Structure from motion) 是一种三维重建的方法,用于从motion中实现3D重建。也就是从时间系列的2D图像中推算3D信息。但SfM算法受传统特征检测方法精度的限制,尤其是在复杂场景中
语义分割领域发展迅速,现在可以达到比较高的mIOU,可以考虑使用语义分割模型提取待匹配图像的语义信息,给特征点匹配提供语义约束,提高最后三维重建的精度
《Large-Scale Structure from Motion with Semantic Constraints of Aerial Images》论文就是介绍了这种方法,该论文使用语义约束进行三维点云的重建,精度提高的同时速度也变快了
本项目利用PaddleSeg模块训练Transfomer类的语义分割模型,在UDD数据集中mIOU达到74.50% ,原论文使用DeepLabV3+的mIOU为73.18%,高1.32%
Benchmark
| dataset | model | OA | mIoU | size |
|---|---|---|---|---|
| UDD5 | GCN | 88.57% | 73.17% | 302M |
| UDD5 | ENet | 88.14% | 71.38% | 5.5M |
| UDD6 | GCN | 86.54% | 72.58% | 302M |
| UDD6 | ENet | 85.20% | 69.44% | 5.5M |
| UDD6 | DeepLab V3+ | 86.90% | 73.18% | 721M |
| Class | Gt Label | RGB |
|---|---|---|
| Other | 0 | (0,0,0) |
| Facade | 1 | (102,102,156) |
| Road | 2 | (128,64,128) |
| Vegetation | 3 | (107,142,35) |
| Vehicle | 4 | (0,0,142) |
| Roof | 5 | (70,70,70) |
# clone PaddleSeg的项目!git clone https://gitee.com/paddlepaddle/PaddleSeg
正克隆到 'PaddleSeg'... remote: Enumerating objects: 16439, done. remote: Counting objects: 100% (1402/1402), done. remote: Compressing objects: 100% (811/811), done. remote: Total 16439 (delta 710), reused 1166 (delta 573), pack-reused 15037 接收对象中: 100% (16439/16439), 341.09 MiB | 4.75 MiB/s, 完成. 处理 delta 中: 100% (10574/10574), 完成. 检查连接... 完成。
#解压数据集,有两个数据集,本项目使用UDD6!mkdir work/UDD6 !unzip -oq data/data75675/UDD6.zip -d work/UDD6/
# 对数据进行crop,具体细节可查看process_data.py的代码%cd work/ !python process_data.py --tag val #处理验证集!python process_data.py --tag train #处理训练集
/home/aistudio/work mkdir UDD6/val_sub ... [>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 35/35, 6.0 task/s, elapsed: 6s, ETA: 0sAll processes done. mkdir UDD6/val_labels_sub ... [>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 35/35, 25.0 task/s, elapsed: 1s, ETA: 0sAll processes done. mkdir UDD6/train_sub ... [>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 106/106, 6.0 task/s, elapsed: 18s, ETA: 0sAll processes done. mkdir UDD6/train_labels_sub ... [>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 106/106, 26.4 task/s, elapsed: 4s, ETA: 0sAll processes done.
# 安装依赖%cd /home/aistudio/PaddleSeg !pip install -r requirements.txt
# 训练数据集txt生成!python tools/split_dataset_list.py \
../work/UDD6 train_sub train_labels_sub \
--split 1.0 0.0 0.0 \
--format JPG png \
--label_class Other Facade Road Vegetation Vehicle Roof!mv ../work/UDD6/train.txt ../work/UDD6/train_true.txt # 修改文件名
# 验证数据集txt生成!python tools/split_dataset_list.py \
../work/UDD6 val_sub val_labels_sub \
--split 0.0 1.0 0.0 \
--format JPG png \
--label_class Other Facade Road Vegetation Vehicle Roof!rm ../work/UDD6/train.txt #删除第二次运行生成的train.txt!mv ../work/UDD6/train_true.txt ../work/UDD6/train.txt # 将文件名改回来
# 新建.yml文件,然后将以下信息写入#!touch configs/segformer_b3_UDD.yml# 也可以直接复制准备好的文件放入该文件夹下!cp ../work/segformer_b3_UDD.yml configs/
batch_size: 2iters: 40000train_dataset:
type: Dataset
dataset_root: ../work/UDD6/
train_path: ../work/UDD6/train.txt
num_classes: 6
transforms:
- type: ResizeStepScaling
min_scale_factor: 0.5
max_scale_factor: 2.0
scale_step_size: 0.25
- type: RandomPaddingCrop
crop_size: [1024, 1024] - type: RandomHorizontalFlip
- type: RandomDistort
brightness_range: 0.4
contrast_range: 0.4
saturation_range: 0.4
- type: Normalize
mode: trainval_dataset:
type: Dataset
dataset_root: ../work/UDD6/
val_path: ../work/UDD6/val.txt
num_classes: 6
transforms:
- type: Normalize
mode: valmodel:
type: SegFormer_B3
num_classes: 6
pretrained: https://bj.bcebos.com/paddleseg/dygraph/mix_vision_transformer_b3.tar.gzoptimizer:
type: sgdlr_scheduler:
type: PolynomialDecay
learning_rate: 0.001
power: 0.9loss:
types:
- type: CrossEntropyLoss
coef: [1]# 开始训练,模型权重保存在output文件夹中,output/best_model 文件夹中为性能最好的模型!export CUDA_VISIBLE_DEVICES=0 # 设置1张可用的卡# windows下请执行以下命令# set CUDA_VISIBLE_DEVICES=0!python train.py \
--config configs/segformer_b3_UDD.yml \
--do_eval \
--use_vdl \
--save_interval 500 \
--save_dir output!python val.py \
--config configs/segformer_b3_UDD.yml \
--model_path output/best_model/model.pdparams \!mv ../work/UDD6/val ../work/
!python predict.py \
--config ../work/segformer_b3_UDD.yml \
--model_path ../work/best_model/model.pdparams \
--image_path ../work/val/src \
--save_dir ../work/val/result \
--is_slide \
--crop_size 1024 1024 \
--stride 512 512# 展示预测的结果import matplotlib.pyplot as pltfrom PIL import Image
output = Image.open(r"../work/val/result/added_prediction/000061.JPG")
plt.figure(figsize=(20,24))#设置窗口大小plt.imshow(output), plt.axis('off')(<matplotlib.image.AxesImage at 0x7f2bdae02710>, (-0.5, 4095.5, 2159.5, -0.5))
<Figure size 1440x1728 with 1 Axes>
以上就是PaddleSeg:使用Transformer模型对航空遥感图像分割的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号