{"id":13507070,"url":"https://github.com/justchenhao/STANet","last_synced_at":"2025-03-30T07:32:00.410Z","repository":{"id":39492928,"uuid":"266118630","full_name":"justchenhao/STANet","owner":"justchenhao","description":"official implementation of the spatial-temporal attention neural network (STANet) for remote sensing image change detection","archived":false,"fork":false,"pushed_at":"2023-03-11T13:56:15.000Z","size":1967,"stargazers_count":377,"open_issues_count":55,"forks_count":107,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-02-17T14:35:51.992Z","etag":null,"topics":["attention-mechanism","change-detection","contrastive-loss","dataset","remote-sensing","siamese-neural-network"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justchenhao.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}},"created_at":"2020-05-22T13:34:25.000Z","updated_at":"2024-02-15T16:48:30.000Z","dependencies_parsed_at":"2022-07-20T03:03:40.295Z","dependency_job_id":"497c1be4-62b8-4a89-ac56-17931551e816","html_url":"https://github.com/justchenhao/STANet","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"6152d72f55df00a43d341580970be7a58c6b0cd5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justchenhao%2FSTANet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justchenhao%2FSTANet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justchenhao%2FSTANet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justchenhao%2FSTANet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justchenhao","download_url":"https://codeload.github.com/justchenhao/STANet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213449952,"owners_count":15588998,"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","contrastive-loss","dataset","remote-sensing","siamese-neural-network"],"created_at":"2024-08-01T02:00:21.939Z","updated_at":"2024-08-01T02:00:50.681Z","avatar_url":"https://github.com/justchenhao.png","language":"Python","funding_links":[],"categories":["2 Code","Python"],"sub_categories":["2.1 Multispectral"],"readme":"# STANet for remote sensing image change detection\n\nIt is the implementation of the paper: A Spatial-Temporal Attention-Based Method and a New Dataset for Remote Sensing Image Change Detection.\n\nHere, we provide the pytorch implementation of the spatial-temporal attention neural network (STANet) for remote sensing image change detection.\n\n![image-20200601213320103](/src/stanet-overview.png)\n\n## Change log\n20230311：\n\n- We have supplemented geospatial information (e.g., latitude and longitude coordinates) for each sample in LEVIR_CD. Specifically, we provide a `geojson` file and a `json` file, both of which contains the correspondence of the sample name and the geospatial location. Files and more information can be seen in the `LEVIR_CD_spatial_info` folder. \n\n20210112:\n\n- add the pretraining weight of PAM. [baidupan link](https://pan.baidu.com/s/1O1kg7JWunqd87ajtVMM6pg), code: 2rja\n\n20201105：\n\n- add a demo for quick start.\n- add more dataset loader modes.\n- enhance the image augmentation module (crop and rotation).\n\n20200601：\n\n- first commit\n\n## Prerequisites\n\n- windows or Linux \n- Python 3.6+\n- CPU or NVIDIA GPU\n- CUDA 9.0+\n- PyTorch \u003e 1.0\n- visdom\n\n## Installation\n\nClone this repo:\n\n```bash\ngit clone https://github.com/justchenhao/STANet\ncd STANet\n```\n\nInstall [PyTorch](http://pytorch.org/) 1.0+ and other dependencies (e.g., torchvision, [visdom](https://github.com/facebookresearch/visdom) and [dominate](https://github.com/Knio/dominate))\n\n## Quick Start\n\nYou can run a demo to get started. \n\n```bash\npython demo.py\n```\n\nThe input samples are in `samples`. After successfully run this script, you can find the predicted results in `samples/output`.\n\n## Prepare Datasets\n\n### download the change detection dataset\n\nYou could download the LEVIR-CD at https://justchenhao.github.io/LEVIR/;\n\nThe path list in the downloaded folder is as follows:\n\n```\npath to LEVIR-CD:\n                ├─train\n                │  ├─A\n                │  ├─B\n                │  ├─label\n                ├─val\n                │  ├─A\n                │  ├─B\n                │  ├─label\n                ├─test\n                │  ├─A\n                │  ├─B\n                │  ├─label\n```\n\nwhere A contains images of pre-phase, B contains images of post-phase, and label contains label maps.\n\n### cut bitemporal image pairs\n\nThe original image in LEVIR-CD has a size of 1024 * 1024, which will consume too much memory when training. Therefore, we can cut the origin images into smaller patches (e.g., 256 * 256, or 512 * 512).  In our paper, we cut the original image into patches of 256 * 256 size without overlapping.\n\nMake sure that the corresponding patch samples in the A, B, and label subfolders have the same name.\n\n## Train\n\n### Monitor training status\n\nTo view training results and loss plots, run this script and click the URL [http://localhost:8097](http://localhost:8097/).\n\n```bash\npython -m visdom.server\n```\n\n### train with our base method\n\nRun the following script:\n\n```bash\npython ./train.py --save_epoch_freq 1 --angle 15 --dataroot path-to-LEVIR-CD-train --val_dataroot path-to-LEVIR-CD-val --name LEVIR-CDF0 --lr 0.001 --model CDF0 --batch_size 8 --load_size 256 --crop_size 256 --preprocess rotate_and_crop\n```\n\nOnce finished, you could find the best model and the log files in the project folder.\n\n### train with Basic spatial-temporal Attention Module (BAM) method\n\n```bash\npython ./train.py --save_epoch_freq 1 --angle 15 --dataroot path-to-LEVIR-CD-train --val_dataroot path-to-LEVIR-CD-val --name LEVIR-CDFA0 --lr 0.001 --model CDFA --SA_mode BAM --batch_size 8 --load_size 256 --crop_size 256 --preprocess rotate_and_crop\n```\n\n### train with Pyramid spatial-temporal Attention Module (PAM) method\n\n```bash\npython ./train.py --save_epoch_freq 1 --angle 15 --dataroot path-to-LEVIR-CD-train --val_dataroot path-to-LEVIR-CD-val --name LEVIR-CDFAp0 --lr 0.001 --model --SA_mode PAM CDFA --batch_size 8 --load_size 256 --crop_size 256 --preprocess rotate_and_crop\n```\n\n## Test\n\nYou could edit the file val.py, for example:\n\n```python\nif __name__ == '__main__':\n    opt = TestOptions().parse()   # get training options\n    opt = make_val_opt(opt)\n    opt.phase = 'test'\n    opt.dataroot = 'path-to-LEVIR-CD-test' # data root \n    opt.dataset_mode = 'changedetection'\n    opt.n_class = 2\n    opt.SA_mode = 'PAM' # BAM | PAM \n    opt.arch = 'mynet3'\n    opt.model = 'CDFA' # model type\n    opt.name = 'LEVIR-CDFAp0' # project name\n    opt.results_dir = './results/' # save predicted images \n    opt.epoch = 'best-epoch-in-val' # which epoch to test\n    opt.num_test = np.inf\n    val(opt)\n```\n\nthen run the script: `python val.py`. Once finished, you can find the prediction log file in the project directory and predicted image files in the result directory.\n\n## Using other dataset mode\n\n### List mode\n\n```bash\nlist=train\nlr=0.001\ndataset_mode=list\ndataroot=path-to-dataroot\nname=project_name\n\npython ./train.py --num_threads 4 --display_id 0 --dataroot ${dataroot} --val_dataroot ${dataroot} --save_epoch_freq 1 --niter 100 --angle 15 --niter_decay 100  --display_env FAp0 --SA_mode PAM --name $name --lr $lr --model CDFA --batch_size 4 --dataset_mode $dataset_mode --val_dataset_mode $dataset_mode --split $list --load_size 256 --crop_size 256 --preprocess resize_rotate_and_crop\n```\n\nIn this case, the data structure should be the following:\n\n```\n\"\"\"\ndata structure\n-dataroot\n    ├─A\n        ├─train1.png\n        ...\n    ├─B\n        ├─train1.png\n        ...\n    ├─label\n        ├─train1.png\n        ...\n    └─list\n        ├─val.txt\n        ├─test.txt\n        └─train.txt\n\n# In list/train.txt, each low writes the filename of each sample,\n   # for example:\n       list/train.txt\n           train1.png\n           train2.png\n           ...\n\"\"\"\n```\n\n### Concat mode for loading multiple datasets (each default mode is List)\n\n```bash\nlist=train\nlr=0.001\ndataset_type=CD_data1,CD_data2,...,\nval_dataset_type=CD_data\ndataset_mode=concat\nname=project_name\n\npython ./train.py --num_threads 4 --display_id 0 --dataset_type $dataset_type --val_dataset_type $val_dataset_type --save_epoch_freq 1 --niter 100 --angle 15 --niter_decay 100  --display_env FAp0 --SA_mode PAM --name $name --lr $lr --model CDFA --batch_size 4 --dataset_mode $dataset_mode --val_dataset_mode $dataset_mode --split $list --load_size 256 --crop_size 256 --preprocess resize_rotate_and_crop\n```\n\nNote, in this case, you should modify the `get_dataset_info` in `data/data_config.py` to add the corresponding ` dataset_name` and `dataroot` in it.\n\n```python\nif dataset_type == 'LEVIR_CD':\n    root = 'path-to-LEVIR_CD-dataroot'\nelif ...\n# add more dataset ...\n```\n\n## Other TIPS\n\nFor more Training/Testing guides, you could see the option files in the  `./options/`  folder.\n\n## Citation\n\nIf you use this code for your research, please cite our papers.\n\n```\n@Article{rs12101662,\nAUTHOR = {Chen, Hao and Shi, Zhenwei},\nTITLE = {A Spatial-Temporal Attention-Based Method and a New Dataset for Remote Sensing Image Change Detection},\nJOURNAL = {Remote Sensing},\nVOLUME = {12},\nYEAR = {2020},\nNUMBER = {10},\nARTICLE-NUMBER = {1662},\nURL = {https://www.mdpi.com/2072-4292/12/10/1662},\nISSN = {2072-4292},\nDOI = {10.3390/rs12101662}\n}\n```\n\n## Acknowledgments\n\nOur code is inspired by [pytorch-CycleGAN](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix).\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustchenhao%2FSTANet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustchenhao%2FSTANet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustchenhao%2FSTANet/lists"}