本文围绕遥感变化检测项目展开,参考多个相关项目,指出存在随机bug及解决办法。其在相同训练轮数下精度提升明显,还分享了调参思路,涉及数据集、模型、训练超参、后处理等方面。此外,详述了数据预处理、网络训练、测试、推理等流程,并附相关报错及统计数据。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

本项目实现参考了以下项目,
PaddleRS版的baseline(以下简称原bl),个人测试精度为0.768,同样的配置在本项目PaddleCD下,个人测试精度则为0.764
该项目存在随机bug,暂时不知道原因以及彻底解决方法;如果出现特定报错内容(详见文末附录1),重启后重新执行代码一般可以解决;建议在理解代码的情况下,尝试在PaddleRS中修改运行
该项目在与原bl相同训练轮数下,bit单模精度达到0.86221,训练日志手动保存在model_log/bit_hr18.txt中;按照调参思路进行调整,bit单模精度可以达到0.889+;
感谢 @古代飞 大佬的baseline, 感谢@开着奔驰种地、@我不是南通 以及群内各位大佬的经验分享
为方便阅读,以下内容中提到的xx%为调参涨点,是使用trick后提交分数的百分比变化
但因个人实验记录不完善、实验内容过多未完全控制变量 以及 某些玄学问题,以下调参涨点可能存在误差,仅供参考
A、B时相的训练集、测试集、全集的均值标准差统计如下(因显示问题采用图片格式,文字格式详见文末附录2):
由统计数据可见:A、B时相的均值标准差存在较大差异,但训练集与验证集差异较小
针对光谱差异问题,尝试了3种解决方案:
RandomDistort
训练集共637共1024*1024样本,测试集共363个1024*1024样本,训练测试比约2:1
原bl中,针对该问题的解决方案是从原始样本中随机裁剪部分区域并resize为256*256。
个人尝试了2种方法:
经过统计,背景与变化类别的像素占比为95.3:4.6,类别严重不均衡,并且变化类别仅在573个样本中存在(统计数据见附录2)
针对上述问题,可以采用以下解决方案:
在CV下游任务中,任务精度往往与backbone的特征表达能力有关,原bl中的backbone为resnet18,结构较为简单 针对该问题,采用以下解决方案:
resnet18-->hrnet18
可以修改以下超参数:
more steplr = 0.0004adamw optimizer RandomCrop 384RandomFlipOrRotationRandoBlurRandomSwap
后处理有多种方式,针对训练时采用的数据增强策略,可以采用以下方案:
针对输出结果,有以下方案:
5. 调整阈值/缩放logit值,目的在于识别出更多概率值较小的变化区域
6. 形态学后处理,优化边缘区域
后处理的提升幅度较小且不稳定,一般最后使用
综上,最终在原bl上进行以下修改:
flip预测 缩放logit值 形态学后处理
即 将一个模型的不同结果进行集成
在后处理中使用的flip预测、ms预测属于单模集成的内容
ema、swa等也属于单模集成内容,其主要思路为将不同epoch得到的较好的模型参数进行集成
k折交叉验证,将数据集均分为k份,每次将其中一份作为验证集其余为训练集进行训练
本次竞赛并未使用上述单模集成内容,但据以往经验看,上述内容有一定的提分作用
即 将多个模型的不同结果进行集成
包括硬投票集成和软投票集成,区别在于使用预测的类别结果还是类别得分进行集成
经验表明不同架构的模型相互集成,得分较高
如cutmix、mixup、cutout、mosaic、copypaste等等长得很像的、涉及多个样本之间的数据增强,据说也有效果,目前原bl和本项目暂不支持该系列操作
本次比赛不支持增加数据集;
在其他任务中可以尝试加入未标注的图像,生成伪标签进行监督/自监督
以上为本次比赛中,使用或想到的调参思路,此外还有其他各种trick,大家可以多看论文与经验分享进行总结实验
为鼓励大家动手实践,以上调参思路并未完全在代码中实现,可以根据思路自己动手实践
上述tricke独使用时可能提点较高或较低,但与其他trick组合使用时可能是另一种效果,需要多实践尝试
——————————————————————————————————————分割线——————————————————————————————————————
# 清除cell输出结果def clear_output():
"""
clear output for both jupyter notebook and the console
"""
import os
os.system('cls' if os.name == 'nt' else 'clear') from IPython.display import clear_output as clear
clear()# 解压数据!unzip -oq /home/aistudio/data/data134796/train_data.zip -d /home/aistudio/data/src/ !unzip -oq /home/aistudio/data/data134796/test_data.zip -d /home/aistudio/data/src/
# 安装依赖库!pip install -r /home/aistudio/PaddleCD/requirements.txt clear_output()
# 将0、255修改为0、1!python /home/aistudio/work/data_generate.py /home/aistudio/data/src/train/label# 直接拷贝已有的数据集划分文件,保证每次训练评价指标相同!cp /home/aistudio/work/val.txt /home/aistudio/data/src/val.txt# !cp /home/aistudio/work/train.txt /home/aistudio/data/src/train.txt!cp /home/aistudio/work/train8cp.txt /home/aistudio/data/src/train.txt # 将训练集复制8次,减少每次读取训练集的损耗时间
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/skimage/io/manage_plugins.py:23: UserWarning: Your installed pillow version is < 8.1.2. Several security issues (CVE-2021-27921, CVE-2021-25290, CVE-2021-25291, CVE-2021-25293, and more) have been fixed in pillow 8.1.2 or higher. We recommend to upgrade this library. from .collection import imread_collection_wrapper 100%|█████████████████████████████████████████| 637/637 [00:46<00:00, 13.60it/s]
# 数据统计# !python /home/aistudio/work/data_sta.py
gts class sta:
class sta : 100%|█████████████████████████████| 637/637 [00:06<00:00, 97.32it/s]
bg change
Pixel_sum 636876269 31066643
Pixel_pct 0.953489 0.0465109
Sample_sum 638 573
Sample_pct 0.526837 0.473163
save to /home/aistudio/data/src/train/label.csv
finish# 配置文件路径与模型保存路径# COF_PATH = '/home/aistudio/PaddleCD/bit_config/bit_baseline.yml'# MD_PATH = '/home/aistudio/best_model/bit_baseline.pdparams'# COF_PATH = '/home/aistudio/PaddleCD/bit_config/bit_res18.yml'# MD_PATH = '/home/aistudio/best_model/bit_res18.pdparams'COF_PATH = '/home/aistudio/PaddleCD/bit_config/bit_hr18.yml'MD_PATH = '/home/aistudio/best_model/bit_hr18.pdparams'
# 模型训练print(COF_PATH.center(100, '*'),'\n\n')print(MD_PATH.center(100, '*'),'\n\n')# 与paddlers训练轮数相同,训练时长55min!python /home/aistudio/PaddleCD/train.py \
--save_dir /home/aistudio/data/output \
--config $COF_PATH \
--do_eval \
--use_vdl \
--iters 3700 \
--save_interval 370 \
--batch_size=16 \
--log_iters 50 \
--num_workers 8 \
--seed 1919810
# 后台训练时,需要清空输出,保证notebook正常导入;notebook训练时,可以不用# clear_output()# 将最优模型拷贝到/home/aistudio/best_model路径下,将训练日志拷贝到/home/aistudio/model_log路径下!mkdir /home/aistudio/best_model/
!cp /home/aistudio/data/output/best_model/model.pdparams $MD_PATH
!find /home/aistudio/data/output -name '*.log' -exec cp -t /home/aistudio/model_log/ "{}" +# 普通测试!python /home/aistudio/PaddleCD/val.py \
--batch_size 1 \
--config $COF_PATH \
--model_path $MD_PATH# 增强测试,加入翻转预测!python /home/aistudio/PaddleCD/val.py \
--aug_eval \
--flip_vertical \
--batch_size 1 \
--config $COF_PATH \
--model_path $MD_PATH# # 增强测试,加入多尺度预测# !python /home/aistudio/PaddleCD/val.py \# --aug_eval \# --flip_vertical \# --batch_size 1 \# --scales 0.5 1.0 2.0\# --config $COF_PATH \# --model_path $MD_PATH
# # 增强测试,加入交换预测# !python /home/aistudio/PaddleCD/val.py \# --aug_eval \# --swap 7\# --flip_vertical \# --batch_size 1 \# --scales 0.5 1.0 2.0\# --config $COF_PATH \# --model_path $MD_PATH
# 普通推理,推理结果保存在/home/aistudio/data/src/result下# bit_hr18推理时长为1分35秒!python /home/aistudio/PaddleCD/predict.py \
--config $COF_PATH \
--model_path $MD_PATH \
--image_path /home/aistudio/data/src/test/A \
--image_path2 /home/aistudio/data/src/test/B \
--batch_size 32 \
--save_dir /home/aistudio/data/src# 增强推理,加入翻转预测,推理结果保存在/home/aistudio/data/src/result下# bit_hr18推理时长为2分46秒!python /home/aistudio/PaddleCD/predict.py \
--config $COF_PATH \
--model_path $MD_PATH \
--image_path /home/aistudio/data/src/test/A \
--image_path2 /home/aistudio/data/src/test/B \
--aug_pred \
--flip_vertical \
--batch_size 1 \
--save_dir /home/aistudio/data/src# # 增强推理,加入多尺度预测,推理结果保存在/home/aistudio/data/src/result下# !python /home/aistudio/PaddleCD/predict.py \# --config $COF_PATH \# --model_path $MD_PATH \# --image_path /home/aistudio/data/src/test/A \# --image_path2 /home/aistudio/data/src/test/B \# --aug_pred \# --flip_vertical \# --batch_size 1 \# --scales 0.5 1.0 2.0 \# --save_dir /home/aistudio/data/src
# # 增强推理,加入交换预测推理结果保存在/home/aistudio/data/src/result下# !python /home/aistudio/PaddleCD/predict.py \# --config $COF_PATH \# --model_path $MD_PATH \# --image_path /home/aistudio/data/src/test/A \# --image_path2 /home/aistudio/data/src/test/B \# --aug_pred \# --swap 7 \# --flip_vertical \# --batch_size 1 \# --scales 0.5 1.0 2.0 \# --save_dir /home/aistudio/data/src
# # 滑窗增强推理,推理结果保存在/home/aistudio/data/src/result下# bit_hr18推理时长为12分# !python /home/aistudio/PaddleCD/predict.py \# --config $COF_PATH \# --model_path $MD_PATH \# --image_path /home/aistudio/data/src/test/A \# --image_path2 /home/aistudio/data/src/test/B \# --aug_pred \# --flip_vertical \# --is_slide \# --batch_size 1 \# --patch_size 16 \# --crop_size 384 384 \# --stride 128 128 \# --save_dir /home/aistudio/data/src
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/skimage/io/manage_plugins.py:23: UserWarning: Your installed pillow version is < 8.1.2. Several security issues (CVE-2021-27921, CVE-2021-25290, CVE-2021-25291, CVE-2021-25293, and more) have been fixed in pillow 8.1.2 or higher. We recommend to upgrade this library.
from .collection import imread_collection_wrapper
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Sized
2022-05-29 16:54:15 [INFO]
---------------Config Information---------------
batch_size: 16
iters: 20000
loss:
coef:
- 1
types:
- type: CrossEntropyLoss
lr_scheduler:
gamma: 0.5
learning_rate: 0.0004
step_size: 1000
type: StepDecay
model:
backb: hrnet18
in_channels: 3
num_classes: 2
type: BIT
optimizer:
type: AdamW
train_dataset:
dataset_root: /home/aistudio/data/src/
mode: train
num_classes: 2
train_path: /home/aistudio/data/src/train.txt
transforms:
- aspect_ratio:
- 1.0
- 1.0
crop_size:
- 384
- 384
scaling:
- 0.25
- 1.0
type: RandomCrop
- probs:
- 0.6
- 0.0
probsf:
- 0.4
- 0.4
- 0.2
- 0.0
- 0.0
probsr:
- 0.0
- 0.0
- 0.0
type: RandomFlipOrRotation
- type: RandomDistort
- type: RandomBlur
- type: RandomSwap
- mean:
- 0.5
- 0.5
- 0.5
std:
- 0.5
- 0.5
- 0.5
type: Normalize
type: RSCD
val_dataset:
dataset_root: /home/aistudio/data/src/
mode: val
transforms:
- mean:
- 0.5
- 0.5
- 0.5
std:
- 0.5
- 0.5
- 0.5
type: Normalize
type: RSCD
val_path: /home/aistudio/data/src/val.txt
------------------------------------------------
W0529 16:54:15.094134 14743 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0529 16:54:15.094177 14743 device_context.cc:465] device: 0, cuDNN Version: 7.6.
2022-05-29 16:54:18 [INFO] Loading pretrained model from https://bj.bcebos.com/paddleseg/dygraph/hrnet_w18_ssld.tar.gz
2022-05-29 16:54:19 [INFO] There are 1525/1525 variables loaded into HRNet.
2022-05-29 16:54:19 [INFO] Number of predict images = 363
2022-05-29 16:54:19 [INFO] Loading pretrained model from /home/aistudio/best_model/bit_hr18.pdparams
2022-05-29 16:54:20 [INFO] There are 1653/1653 variables loaded into BIT.
2022-05-29 16:54:20 [INFO] Start to predict...
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
/home/aistudio/PaddleCD/paddleseg/core/infer.py:213: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
rows = np.int(np.ceil(1.0 * (h_im - h_crop) / h_stride)) + 1
/home/aistudio/PaddleCD/paddleseg/core/infer.py:214: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
cols = np.int(np.ceil(1.0 * (w_im - w_crop) / w_stride)) + 1
363/363 [==============================] - 738s 2s/ste# 将0、1变为0、255!python /home/aistudio/work/data_postprocess.py
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/skimage/io/manage_plugins.py:23: UserWarning: Your installed pillow version is < 8.1.2. Several security issues (CVE-2021-27921, CVE-2021-25290, CVE-2021-25291, CVE-2021-25293, and more) have been fixed in pillow 8.1.2 or higher. We recommend to upgrade this library. from .collection import imread_collection_wrapper 96%|███████████████████████████████████████▏ | 347/363 [00:18<00:00, 20.46it/s]
# 结果打包!zip -j /home/aistudio/submisson.zip /home/aistudio/data/src/result/* > /dev/null
——————————————————————————————————————分割线——————————————————————————————————————
SystemError: (Fatal) DataLoader process (pid 1. If run DataLoader by DataLoader.from_generator(...), queue capacity is set by from_generator(..., capacity=xx, ...). 2. If run DataLoader by DataLoader(dataset, ...), queue capacity is set as 2 times of the max value of num_workers and len(places). 3. If run by DataLoader(dataset, ..., use_shared_memory=True), set use_shared_memory=False for not using shared memory.) exited is killed by signal: 2992. It may be caused by insufficient shared storage space. This problem usually occurs when using docker as a development environment. Please use command `df -h` to check the storage space of `/dev/shm`. Shared storage space needs to be greater than (DataLoader Num * DataLoader queue capacity * 1 batch data size). You can solve this problem by increasing the shared storage space or reducing the queue capacity appropriately. Bus error (at /paddle/paddle/fluid/imperative/data_loader.cc:177)
bg changePixel_sum 636876269 31066643Pixel_pct 0.953489 0.0465109Sample_sum 638 573Sample_pct 0.526837 0.473163
以上就是【方案分享】第十一届 “中国软件杯”大学生软件设计大赛遥感解译赛道 比赛方案分享的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号