MergeSAM: Unsupervised Change Detection of Remote Sensing Images Based on the Segment Anything Model
IGARSS 2025 | PyTorch Implementation
Official PyTorch implementation of the IGARSS 2025 paper:
“MergeSAM: Unsupervised Change Detection of Remote Sensing Images Based on the Segment Anything Model (SAM)”
- Paper (arXiv): https://arxiv.org/abs/2507.22675
- WeChat post: https://mp.weixin.qq.com/s/EBGxqvBYl832S8MyHi9Q5w
Abstract
Recently, large foundation models trained on vast datasets have demonstrated exceptional capabilities in feature extraction and general feature representation. The ongoing advancements in deep learning-driven large models have shown great promise in accelerating unsupervised change detection methods, thereby enhancing the practical applicability of change detection technologies. Building on this progress, this paper introduces MergeSAM, an innovative unsupervised change detection method for high-resolution remote sensing imagery, based on the Segment Anything Model (SAM). Two novel strategies, MaskMatching and MaskSplitting, are designed to address real-world complexities such as object splitting, merging, and other intricate changes. The proposed method fully leverages SAM's object segmentation capabilities to construct multitemporal masks that capture complex changes, embedding the spatial structure of land cover into the change detection process.
以下以
maincode.py为例。
- !!!无需从SAM官方仓库下载segment anything项目,请使用我们上传的segment-anything项目,我们在automatic_mask_generator.py中进行了修改,增加了SamAutomaticMaskGenerator.generate_onlyMask_Embed函数。
- 在
maincode.py第 7 行修改为你的本地路径(示例):
# line 7
SAM_PROJECT_PATH = "/absolute/path/to/segment-anything"
import sys; sys.path.append(SAM_PROJECT_PATH)- 下载权重文件(示例:
sam_vit_h_4b8939.pth、sam_vit_l_0b3195.pth、sam_vit_b_01ec64.pth)。 - 在
maincode.py第 27、29、31 行将sam_checkpoint替换为你的权重路径(示例):
# lines 27 / 29 / 31 (examples)
sam_checkpoint_h = "/absolute/path/to/sam_vit_h_4b8939.pth"
sam_checkpoint_l = "/absolute/path/to/sam_vit_l_0b3195.pth"
sam_checkpoint_b = "/absolute/path/to/sam_vit_b_01ec64.pth"- 下载 GZ_CD_data 或其它二值变化检测数据集并解压。
- 在
maincode.py第 146 行设置数据根目录(示例):
# line 146
img_root = "/absolute/path/to/GZ_CD_data"- GZ_CD_data(百度网盘):https://pan.baidu.com/s/1TpeUDKIUH3iUXSsEe04YLg?pwd=359n 提取码:359n
- 推荐环境:Python ≥ 3.10
- GPU: ≥ RTX2080
- 运行:
python maincode.py注意:若行号不一致,请根据注释语义定位变量(
SAM_PROJECT_PATH、sam_checkpoint、img_root)。如需切换 SAM 变体(H/L/B),请确保权重文件与模型配置匹配。
Thanks to the following repository: AnyChange.


