File size: 7,358 Bytes
b59f460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f0ea9c
 
b59f460
5f0ea9c
 
 
 
 
 
b59f460
5f0ea9c
b59f460
 
5f0ea9c
b59f460
5f0ea9c
b59f460
5f0ea9c
 
 
 
b59f460
5f0ea9c
b59f460
5f0ea9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b59f460
 
5f0ea9c
b59f460
5f0ea9c
b59f460
5f0ea9c
 
 
 
 
 
b59f460
5f0ea9c
b59f460
5f0ea9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b59f460
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320

<div align="center">
 
#  CSSM
**Efficient Remote Sensing Change Detection with Change State Space Models**

[**E.Ghazaei**](https://scholar.google.com/citations?user=R-ghC00AAAAJ&hl=en), [**E.Aptoula**](https://sites.google.com/view/erchan-aptoula/) 

 Faculty of Engineering and Natural Sciences (VPALab), Sabanci University, Istanbul, Turkiye

[[Paper Link](https://arxiv.org/abs/2504.11080)] 
</div>



## πŸ›ŽοΈUpdates
* **` Notice🐍🐍`**: CSSM has been accepted by [IEEE GRSL](https://ieeexplore.ieee.org/xpl/RecentIssue.jsp?punumber=8859)! We'd appreciate it if you could give this repo a ⭐️**star**⭐️ and stay tuned!!
* **` Nov 05th, 2025`**: The CSSM model and training code uploaded. You are welcome to use them!!




---


## πŸš€ Overview


* [**CSSM**]() serves as an efficient and state-of-the-art (SOTA) benchmark for binary change detection.



<p align="center">
  
<img width="1395" height="579" alt="Screenshot from 2025-11-03 16-28-31" src="https://github.com/user-attachments/assets/dccfdfc5-98b4-443d-b170-07e5e3ec551d" />
</p>


---


## πŸ“¦ Requirements
```bash

pip install torch torchvision torchaudio
pip install  pillow
pip install numpy scipy pandas
pip install matplotlib seaborn
pip install einops 
pip install torchinfo

```


---

## πŸ“ Dataset Preparation

This project supports three main change detection datasets:
- **LEVIR-CD+** - [Download](https://www.kaggle.com/datasets/mdrifaturrahman33/levir-cd-change-detection)
- **SYSU-CD** - [Download](https://github.com/liumency/SYSU-CD)
- **WHU-CD** - [Download](http://gpcv.whu.edu.cn/data/building_dataset.html)

---

### Dataset Structure

#### For LEVIR-CD:
```
your_dataset/
β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ A/          # Pre-change images
β”‚   β”œβ”€β”€ B/          # Post-change images
β”‚   └── label/      # Ground truth masks
β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ A/
β”‚   β”œβ”€β”€ B/
β”‚   └── label/
└── val/
    β”œβ”€β”€ A/
    β”œβ”€β”€ B/
    └── label/
```


#### For SYSU-CD:
```
your_dataset/
β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ time1/          # Pre-change images
β”‚   β”œβ”€β”€ time2/          # Post-change images
β”‚   └── label/      # Ground truth masks
β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ time1/
β”‚   β”œβ”€β”€ time2/
β”‚   └── label/
└── val/
    β”œβ”€β”€ time1/
    β”œβ”€β”€ time2/
    └── label/
```

#### For WHU-CD:
```
WHU-CD/
β”œβ”€β”€ A/              # Pre-change images
β”œβ”€β”€ B/              # Post-change images
β”œβ”€β”€ label/          # Ground truth masks
β”œβ”€β”€ train_list.txt  # List of training samples
β”œβ”€β”€ test_list.txt   # List of test samples
└── val_list.txt    # List of validation samples
```

The text files should contain image names (one per line):
```
image_001.png
image_002.png
image_003.png
...
```
---

## πŸš‚ Training

### LEVIR-CD Dataset
```bash
python main.py \
    --dataset levir \
    --train_path /path/to/LEVIR-CD/train \
    --test_path /path/to/LEVIR-CD/test \
    --val_path /path/to/LEVIR-CD/val \
    --batch_size 64 \
    --epochs 50 \
    --lr 0.001
```

### SYSU-CD Dataset
```bash
python main.py \
    --dataset sysu \
    --train_path /path/to/SYSU-CD/train \
    --test_path /path/to/SYSU-CD/test \
    --val_path /path/to/SYSU-CD/val \
    --batch_size 32 \
    --epochs 100 \
    --lr 0.0001
```

### WHU-CD Dataset
```bash
python main.py \
    --dataset whu \
    --train_path /path/to/WHU-CD \
    --train_txt /path/to/train_list.txt \
    --test_txt /path/to/test_list.txt \
    --val_txt /path/to/val_list.txt \
    --batch_size 64 \
    --epochs 50
```
---

## βš™οΈ Arguments

### Required Arguments

| Argument | Description | Example |
|----------|-------------|---------|
| `--dataset` | Dataset type: `levir`, `sysu`, or `whu` | `--dataset levir` |
| `--train_path` | Path to training data | `--train_path /data/train` |
| `--test_path` | Path to test data (not for WHU) | `--test_path /data/test` |
| `--val_path` | Path to validation data (not for WHU) | `--val_path /data/val` |

### WHU-CD Specific Arguments

| Argument | Description | Example |
|----------|-------------|---------|
| `--train_txt` | Training sample list file | `--train_txt train_list.txt` |
| `--test_txt` | Test sample list file | `--test_txt test_list.txt` |
| `--val_txt` | Validation sample list file | `--val_txt val_list.txt` |

### Optional Arguments

| Argument | Default | Description |
|----------|---------|-------------|
| `--batch_size` | 64 | Batch size for training |
| `--epochs` | 50 | Number of training epochs |
| `--lr` | 0.001 | Learning rate |
| `--step_size` | 10 | Learning rate scheduler step size |
| `--save_dir` | ./checkpoints | Directory to save model checkpoints |
| `--model_name` | best_model.pth | Filename for saved model |
| `--seed` | 42 | Random seed for reproducibility |
| `--num_workers` | 4 | Number of data loading workers |

---

## πŸ”§ Advanced Usage Examples

### Custom Save Directory and Model Name
```bash
python main.py \
    --dataset levir \
    --train_path /data/LEVIR-CD/train \
    --test_path /data/LEVIR-CD/test \
    --val_path /data/LEVIR-CD/val \
    --save_dir ./experiments/levir_exp1 \
    --model_name levir_model.pth \
    --epochs 100
```

### Different Learning Rate Schedule
```bash
python main.py \
    --dataset sysu \
    --train_path /data/SYSU-CD/train \
    --test_path /data/SYSU-CD/test \
    --val_path /data/SYSU-CD/val \
    --lr 0.0005 \
    --step_size 20 \
    --epochs 150
```

### Smaller Batch Size (for limited GPU memory)
```bash
python main.py \
    --dataset levir \
    --train_path /data/train \
    --test_path /data/test \
    --val_path /data/val \
    --batch_size 16 \
    --num_workers 2
```

---

## πŸ“€ Output

During training, the script will:
- Display training loss for each batch
- Show validation metrics (IoU, confusion matrix) after each epoch
- Save the best model based on validation IoU
- Display learning rate and epoch time

### Model Checkpoint

The best model is automatically saved to:
```
{save_dir}/{model_name}
```

Default: `./checkpoints/best_model.pth`

---

## πŸ” Troubleshooting

### Paths with Spaces

If your paths contain spaces, wrap them in quotes:
```bash
python main.py \
    --dataset levir \
    --train_path "/path/with spaces/train" \
    --test_path "/path/with spaces/test" \
    --val_path "/path/with spaces/val"
```

### CUDA Out of Memory

Reduce batch size:
```bash
python main.py --dataset levir ... --batch_size 16
```

### Missing WHU Text Files

For WHU dataset, ensure all three text files are provided:
```bash
python main.py \
    --dataset whu \
    --train_path /data/WHU-CD \
    --train_txt train_list.txt \
    --test_txt test_list.txt \
    --val_txt val_list.txt
```

---

## πŸ’‘ Getting Help

View all available arguments:
```bash
python main.py --help
```

---

## πŸ“§ Contact

If you have any questions, please contact Elman Ghazaei at elman.ghazaei@sabanciuniv.edu

---

## Qualitative Analysis:





<p align="center">
<img width="1379" height="357" alt="Screenshot from 2025-11-03 16-38-52" src="https://github.com/user-attachments/assets/c63690af-fd07-40af-b991-2b5b33ff53af" />
</p>

---
# Results

<img width="1365" height="780" alt="Screenshot from 2025-11-03 18-02-18" src="https://github.com/user-attachments/assets/2dabac8d-9ab5-467d-9dbe-6aa5266b2e5f" />