{"id":13785134,"url":"https://github.com/wgcban/ChangeFormer","last_synced_at":"2025-05-11T20:32:14.033Z","repository":{"id":45082799,"uuid":"434410116","full_name":"wgcban/ChangeFormer","owner":"wgcban","description":"[IGARSS'22]: A Transformer-Based Siamese Network for Change Detection","archived":false,"fork":false,"pushed_at":"2024-01-31T15:06:58.000Z","size":14420,"stargazers_count":422,"open_issues_count":5,"forks_count":56,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-06T02:06:23.802Z","etag":null,"topics":["attention-mechanism","change-detection","climate-change","deep-learning","multi-temporal","pytorch","remote-sensing","satellite-imagery","siamese-network","transformer-architecture","transformer-encoder"],"latest_commit_sha":null,"homepage":"https://www.wgcban.com/research#h.e51z61ujhqim","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wgcban.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-02T23:52:06.000Z","updated_at":"2024-09-29T07:50:06.000Z","dependencies_parsed_at":"2022-07-18T16:28:43.234Z","dependency_job_id":"d8d2a552-e3e8-40f0-922b-ba8270a59ef0","html_url":"https://github.com/wgcban/ChangeFormer","commit_stats":{"total_commits":226,"total_committers":3,"mean_commits":75.33333333333333,"dds":"0.46460176991150437","last_synced_commit":"6f7ffb6bf7f5a54092d9078ecbc26ce1b512df3e"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wgcban%2FChangeFormer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wgcban%2FChangeFormer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wgcban%2FChangeFormer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wgcban%2FChangeFormer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wgcban","download_url":"https://codeload.github.com/wgcban/ChangeFormer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253632092,"owners_count":21939371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attention-mechanism","change-detection","climate-change","deep-learning","multi-temporal","pytorch","remote-sensing","satellite-imagery","siamese-network","transformer-architecture","transformer-encoder"],"created_at":"2024-08-03T19:00:57.302Z","updated_at":"2025-05-11T20:32:11.030Z","avatar_url":"https://github.com/wgcban.png","language":"Python","funding_links":[],"categories":["Multispectral"],"sub_categories":["Deep Learning"],"readme":"## ChangeFormer: A Transformer-Based Siamese Network for Change Detection\n\u003e [A Transformer-Based Siamese Network for Change Detection](https://arxiv.org/abs/2201.01293)\n\n\u003e [Wele Gedara Chaminda Bandara](https://www.wgcban.com/), and [Vishal M. Patel](https://engineering.jhu.edu/vpatel36/sciencex_teams/vishalpatel/)\n\n\u003e Presented at [IGARSS-22](https://www.igarss2022.org/default.php), Kuala Lumpur, Malaysia.\n\nUseful links:\n- Paper (published): https://ieeexplore.ieee.org/document/9883686\n- Paper (ArXiv): https://arxiv.org/abs/2201.01293\n- Presentation (in YouTube): https://www.youtube.com/watch?v=SkiNoTrSmQM\n\n## My other Change Detection repos:\n\n- Change Detection with Denoising Diffusion Probabilistic Models: [DDPM-CD](https://github.com/wgcban/ddpm-cd)\n- Semi-supervised Change Detection: [SemiCD](https://github.com/wgcban/SemiCD)\n- Unsupervised Change Detection: [Metric-CD](https://github.com/wgcban/Metric-CD)\n\n\n## Network Architecture\n![image-20210228153142126](./images/IGARS_ChangeFormer.jpeg)\n\n## Quantitative \u0026 Qualitative Results on LEVIR-CD and DSIFN-CD\n![image-20210228153142126](./images/IGARS_ChangeFormer-LEVIR_DSFIN_both.png)\n\n# Usage\n## Requirements\n\n```\nPython 3.8.0\npytorch 1.10.1\ntorchvision 0.11.2\neinops  0.3.2\n```\n\n- Please see `requirements.txt` for all the other requirements.\n\n## Setting up conda environment: \n\nCreate a virtual ``conda`` environment named ``ChangeFormer`` with the following command:\n\n```bash\nconda create --name ChangeFormer --file requirements.txt\nconda activate ChangeFormer\n```\n\n## Installation\n\nClone this repo:\n\n```shell\ngit clone https://github.com/wgcban/ChangeFormer.git\ncd ChangeFormer\n```\n\n## Quick Start on LEVIR dataset\n\nWe have some samples from the [LEVIR-CD](https://justchenhao.github.io/LEVIR/) dataset in the folder `samples_LEVIR` for a quick start.\n\nFirstly, you can download our ChangeFormerV6 pretrained model——by [`Github-LEVIR-Pretrained`](https://github.com/wgcban/ChangeFormer/releases/download/v0.1.0/CD_ChangeFormerV6_LEVIR_b16_lr0.0001_adamw_train_test_200_linear_ce_multi_train_True_multi_infer_False_shuffle_AB_False_embed_dim_256.zip). \n\nPlace it in `checkpoints/ChangeFormer_LEVIR/`.\n\nRun a demo to get started as follows:\n\n```python\npython demo_LEVIR.py\n```\n\nYou can find the prediction results in `samples/predict_LEVIR`.\n\n\n## Quick Start on DSIFN dataset\n\nWe have some samples from the [`DSIFN-CD`](https://github.com/GeoZcx/A-deeply-supervised-image-fusion-network-for-change-detection-in-remote-sensing-images/tree/master/dataset) dataset in the folder `samples_DSIFN` for a quick start.\n\nDownload our ChangeFormerV6 pretrained model——by [`Github`](https://github.com/wgcban/ChangeFormer/releases/download/v0.1.0/CD_ChangeFormerV6_DSIFN_b16_lr0.00006_adamw_train_test_200_linear_ce_multi_train_True_multi_infer_False_shuffle_AB_False_embed_dim_256.zip). After downloaded the pretrained model, you can put it in `checkpoints/ChangeFormer_DSIFN/`.\n\nRun the demo to get started as follows:\n\n```python\npython demo_DSIFN.py\n```\n\nYou can find the prediction results in `samples/predict_DSIFN`.\n\n## Training on LEVIR-CD\n\nWhen we initialy train our ChangeFormer, we initialized some parameters of the network with a model pre-trained on the RGB segmentation (ADE 160k dataset) to get faster convergence.\n\nYou can download the pre-trained model [`Github-LEVIR-Pretrained`](https://github.com/wgcban/ChangeFormer/releases/download/v0.1.0/CD_ChangeFormerV6_LEVIR_b16_lr0.0001_adamw_train_test_200_linear_ce_multi_train_True_multi_infer_False_shuffle_AB_False_embed_dim_256.zip).\n```\nwget https://www.dropbox.com/s/undtrlxiz7bkag5/pretrained_changeformer.pt\n```\n\nThen, update the path to the pre-trained model by updating the ``path`` argument in the ``run_ChangeFormer_LEVIR.sh``.\nHere:\nhttps://github.com/wgcban/ChangeFormer/blob/a3eca2b1ec5d0d2628ea2e0b6beae85630ba79d4/scripts/run_ChangeFormer_LEVIR.sh#L28\n\nYou can find the training script `run_ChangeFormer_LEVIR.sh` in the folder `scripts`. You can run the script file by `sh scripts/run_ChangeFormer_LEVIR.sh` in the command environment.\n\nThe detailed script file `run_ChangeFormer_LEVIR.sh` is as follows:\n\n```cmd\n#!/usr/bin/env bash\n\n#GPUs\ngpus=0\n\n#Set paths\ncheckpoint_root=/media/lidan/ssd2/ChangeFormer/checkpoints\nvis_root=/media/lidan/ssd2/ChangeFormer/vis\ndata_name=LEVIR\n\n\nimg_size=256    \nbatch_size=16   \nlr=0.0001         \nmax_epochs=200\nembed_dim=256\n\nnet_G=ChangeFormerV6        #ChangeFormerV6 is the finalized verion\n\nlr_policy=linear\noptimizer=adamw                 #Choices: sgd (set lr to 0.01), adam, adamw\nloss=ce                         #Choices: ce, fl (Focal Loss), miou\nmulti_scale_train=True\nmulti_scale_infer=False\nshuffle_AB=False\n\n#Initializing from pretrained weights\npretrain=/media/lidan/ssd2/ChangeFormer/pretrained_segformer/segformer.b2.512x512.ade.160k.pth\n\n#Train and Validation splits\nsplit=train         #train\nsplit_val=test      #test, val\nproject_name=CD_${net_G}_${data_name}_b${batch_size}_lr${lr}_${optimizer}_${split}_${split_val}_${max_epochs}_${lr_policy}_${loss}_multi_train_${multi_scale_train}_multi_infer_${multi_scale_infer}_shuffle_AB_${shuffle_AB}_embed_dim_${embed_dim}\n\nCUDA_VISIBLE_DEVICES=1 python main_cd.py --img_size ${img_size} --loss ${loss} --checkpoint_root ${checkpoint_root} --vis_root ${vis_root} --lr_policy ${lr_policy} --optimizer ${optimizer} --pretrain ${pretrain} --split ${split} --split_val ${split_val} --net_G ${net_G} --multi_scale_train ${multi_scale_train} --multi_scale_infer ${multi_scale_infer} --gpu_ids ${gpus} --max_epochs ${max_epochs} --project_name ${project_name} --batch_size ${batch_size} --shuffle_AB ${shuffle_AB} --data_name ${data_name}  --lr ${lr} --embed_dim ${embed_dim}\n```\n\n## Training on DSIFN-CD\n\nFollow the similar procedure mentioned for LEVIR-CD. Use `run_ChangeFormer_DSIFN.sh` in `scripts` folder to train on DSIFN-CD.\n\n## Evaluate on LEVIR\n\nYou can find the evaluation script `eval_ChangeFormer_LEVIR.sh` in the folder `scripts`. You can run the script file by `sh scripts/eval_ChangeFormer_LEVIR.sh` in the command environment.\n\nThe detailed script file `eval_ChangeFormer_LEVIR.sh` is as follows:\n\n```cmd\n#!/usr/bin/env bash\n\ngpus=0\n\ndata_name=LEVIR\nnet_G=ChangeFormerV6 #This is the best version\nsplit=test\nvis_root=/media/lidan/ssd2/ChangeFormer/vis\nproject_name=CD_ChangeFormerV6_LEVIR_b16_lr0.0001_adamw_train_test_200_linear_ce_multi_train_True_multi_infer_False_shuffle_AB_False_embed_dim_256\ncheckpoints_root=/media/lidan/ssd2/ChangeFormer/checkpoints\ncheckpoint_name=best_ckpt.pt\nimg_size=256\nembed_dim=256 #Make sure to change the embedding dim (best and default = 256)\n\nCUDA_VISIBLE_DEVICES=0 python eval_cd.py --split ${split} --net_G ${net_G} --embed_dim ${embed_dim} --img_size ${img_size} --vis_root ${vis_root} --checkpoints_root ${checkpoints_root} --checkpoint_name ${checkpoint_name} --gpu_ids ${gpus} --project_name ${project_name} --data_name ${data_name}\n```\n\n## Evaluate on DSIFN\n\nFollow the same evaluation procedure mentioned for LEVIR-CD. You can find the evaluation script `eval_ChangeFormer_DSFIN.sh` in the folder `scripts`. You can run the script file by `sh scripts/eval_ChangeFormer_DSIFN.sh` in the command environment.\n\n### Dataset Preparation\n\n## Data structure\n\n```\nChange detection data set with pixel-level binary labels；\n├─A\n├─B\n├─label\n└─list\n```\n\n`A`: images of t1 phase;\n\n`B`:images of t2 phase;\n\n`label`: label maps;\n\n`list`: contains `train.txt, val.txt and test.txt`, each file records the image names (XXX.png) in the change detection dataset.\n\n## Links to processed datsets used for train/val/test\n\nYou can download the processed `LEVIR-CD` and `DSIFN-CD` datasets by the DropBox through the following here:\n\n- LEVIR-CD-256: [`click here to download`](https://www.dropbox.com/s/18fb5jo0npu5evm/LEVIR-CD256.zip)\n- DSIFN-CD-256: [`click here to download`](https://www.dropbox.com/s/18fb5jo0npu5evm/LEVIR-CD256.zip)\n\nSince the file sizes are large, I recommed to use command line and cosider downloading the zip file as follows (in linux):\n\nTo download LEVIR-CD dataset run following command in linux-terminal:\n```cmd\nwget https://www.dropbox.com/s/18fb5jo0npu5evm/LEVIR-CD256.zip\n```\nTo download DSIFN-CD dataset run following command in linux-terminal:\n```cmd\nwget https://www.dropbox.com/s/18fb5jo0npu5evm/LEVIR-CD256.zip\n```\n\nFor your reference, I have also attached the inks to original LEVIR-CD and DSIFN-CD here: [`LEVIR-CD`](https://justchenhao.github.io/LEVIR/) and [`DSIFN-CD`](https://github.com/GeoZcx/A-deeply-supervised-image-fusion-network-for-change-detection-in-remote-sensing-images/tree/master/dataset).\n\n### Other useful notes\n#### ChangeFormer for multi-class change detection\nIf you wish to use ChangeFormer for multi-class change detection, you will need to make a few modifications to the existing codebase, which is designed for binary change detection. There are many discussions in the issues section. The required modifications are (https://github.com/wgcban/ChangeFormer/issues/93#issuecomment-1918609871):\n1. `run_ChangeFormer_cd.sh`: n_class=8 and make it a hyperparameter to python main.py\n2. `models/networks.py`: net = ChangeFormerV6(embed_dim=args.embed_dim, output_nc=args.n_class)\n3. `models/basic_model.py`: Comment out: pred_vis = pred * 255, i.e., modifications to visualisation processing\n4. `models/trainer.py`: Modify: ConfuseMatrixMeter(n_class=self.n_class)\n\n### License\n\nCode is released for non-commercial and research purposes **only**. For commercial purposes, please contact the authors.\n\n### Citation\n\nIf you use this code for your research, please cite our paper:\n\n```bibtex\n@INPROCEEDINGS{9883686,\n  author={Bandara, Wele Gedara Chaminda and Patel, Vishal M.},\n  booktitle={IGARSS 2022 - 2022 IEEE International Geoscience and Remote Sensing Symposium}, \n  title={A Transformer-Based Siamese Network for Change Detection}, \n  year={2022},\n  volume={},\n  number={},\n  pages={207-210},\n  doi={10.1109/IGARSS46834.2022.9883686}}\n```\n\n## Disclaimer\nAppreciate the work from the following repositories:\n- https://github.com/justchenhao/BIT_CD (Our ChangeFormer is implemented on the code provided in this repository)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwgcban%2FChangeFormer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwgcban%2FChangeFormer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwgcban%2FChangeFormer/lists"}