Upload README.md
Browse files
README.md
CHANGED
|
@@ -39,32 +39,281 @@
|
|
| 39 |
---
|
| 40 |
|
| 41 |
|
| 42 |
-
##
|
| 43 |
-
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
|
|
|
|
| 49 |
|
|
|
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
<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" />
|
| 54 |
-
</p>
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
---
|
| 57 |
-
# Results
|
| 58 |
|
| 59 |
-
|
| 60 |
|
|
|
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 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 |
+
pip install pillow
|
| 47 |
+
pip install numpy scipy pandas
|
| 48 |
+
pip install matplotlib seaborn
|
| 49 |
+
pip install einops
|
| 50 |
+
pip install torchinfo
|
| 51 |
|
| 52 |
+
```
|
| 53 |
|
| 54 |
|
| 55 |
+
---
|
| 56 |
|
| 57 |
+
## π Dataset Preparation
|
| 58 |
|
| 59 |
+
This project supports three main change detection datasets:
|
| 60 |
+
- **LEVIR-CD+** - [Download](https://www.kaggle.com/datasets/mdrifaturrahman33/levir-cd-change-detection)
|
| 61 |
+
- **SYSU-CD** - [Download](https://github.com/liumency/SYSU-CD)
|
| 62 |
+
- **WHU-CD** - [Download](http://gpcv.whu.edu.cn/data/building_dataset.html)
|
| 63 |
|
| 64 |
+
---
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
### Dataset Structure
|
| 67 |
+
|
| 68 |
+
#### For LEVIR-CD:
|
| 69 |
+
```
|
| 70 |
+
your_dataset/
|
| 71 |
+
βββ train/
|
| 72 |
+
β βββ A/ # Pre-change images
|
| 73 |
+
β βββ B/ # Post-change images
|
| 74 |
+
β βββ label/ # Ground truth masks
|
| 75 |
+
βββ test/
|
| 76 |
+
β βββ A/
|
| 77 |
+
β βββ B/
|
| 78 |
+
β βββ label/
|
| 79 |
+
βββ val/
|
| 80 |
+
βββ A/
|
| 81 |
+
βββ B/
|
| 82 |
+
βββ label/
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
#### For SYSU-CD:
|
| 87 |
+
```
|
| 88 |
+
your_dataset/
|
| 89 |
+
βββ train/
|
| 90 |
+
β βββ time1/ # Pre-change images
|
| 91 |
+
β βββ time2/ # Post-change images
|
| 92 |
+
β βββ label/ # Ground truth masks
|
| 93 |
+
βββ test/
|
| 94 |
+
β βββ time1/
|
| 95 |
+
β βββ time2/
|
| 96 |
+
β βββ label/
|
| 97 |
+
βββ val/
|
| 98 |
+
βββ time1/
|
| 99 |
+
βββ time2/
|
| 100 |
+
βββ label/
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
#### For WHU-CD:
|
| 104 |
+
```
|
| 105 |
+
WHU-CD/
|
| 106 |
+
βββ A/ # Pre-change images
|
| 107 |
+
βββ B/ # Post-change images
|
| 108 |
+
βββ label/ # Ground truth masks
|
| 109 |
+
βββ train_list.txt # List of training samples
|
| 110 |
+
βββ test_list.txt # List of test samples
|
| 111 |
+
βββ val_list.txt # List of validation samples
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
The text files should contain image names (one per line):
|
| 115 |
+
```
|
| 116 |
+
image_001.png
|
| 117 |
+
image_002.png
|
| 118 |
+
image_003.png
|
| 119 |
+
...
|
| 120 |
+
```
|
| 121 |
+
---
|
| 122 |
+
|
| 123 |
+
## π Training
|
| 124 |
+
|
| 125 |
+
### LEVIR-CD Dataset
|
| 126 |
+
```bash
|
| 127 |
+
python main.py \
|
| 128 |
+
--dataset levir \
|
| 129 |
+
--train_path /path/to/LEVIR-CD/train \
|
| 130 |
+
--test_path /path/to/LEVIR-CD/test \
|
| 131 |
+
--val_path /path/to/LEVIR-CD/val \
|
| 132 |
+
--batch_size 64 \
|
| 133 |
+
--epochs 50 \
|
| 134 |
+
--lr 0.001
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
### SYSU-CD Dataset
|
| 138 |
+
```bash
|
| 139 |
+
python main.py \
|
| 140 |
+
--dataset sysu \
|
| 141 |
+
--train_path /path/to/SYSU-CD/train \
|
| 142 |
+
--test_path /path/to/SYSU-CD/test \
|
| 143 |
+
--val_path /path/to/SYSU-CD/val \
|
| 144 |
+
--batch_size 32 \
|
| 145 |
+
--epochs 100 \
|
| 146 |
+
--lr 0.0001
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
### WHU-CD Dataset
|
| 150 |
+
```bash
|
| 151 |
+
python main.py \
|
| 152 |
+
--dataset whu \
|
| 153 |
+
--train_path /path/to/WHU-CD \
|
| 154 |
+
--train_txt /path/to/train_list.txt \
|
| 155 |
+
--test_txt /path/to/test_list.txt \
|
| 156 |
+
--val_txt /path/to/val_list.txt \
|
| 157 |
+
--batch_size 64 \
|
| 158 |
+
--epochs 50
|
| 159 |
+
```
|
| 160 |
---
|
|
|
|
| 161 |
|
| 162 |
+
## βοΈ Arguments
|
| 163 |
|
| 164 |
+
### Required Arguments
|
| 165 |
|
| 166 |
+
| Argument | Description | Example |
|
| 167 |
+
|----------|-------------|---------|
|
| 168 |
+
| `--dataset` | Dataset type: `levir`, `sysu`, or `whu` | `--dataset levir` |
|
| 169 |
+
| `--train_path` | Path to training data | `--train_path /data/train` |
|
| 170 |
+
| `--test_path` | Path to test data (not for WHU) | `--test_path /data/test` |
|
| 171 |
+
| `--val_path` | Path to validation data (not for WHU) | `--val_path /data/val` |
|
| 172 |
|
| 173 |
+
### WHU-CD Specific Arguments
|
| 174 |
|
| 175 |
+
| Argument | Description | Example |
|
| 176 |
+
|----------|-------------|---------|
|
| 177 |
+
| `--train_txt` | Training sample list file | `--train_txt train_list.txt` |
|
| 178 |
+
| `--test_txt` | Test sample list file | `--test_txt test_list.txt` |
|
| 179 |
+
| `--val_txt` | Validation sample list file | `--val_txt val_list.txt` |
|
| 180 |
+
|
| 181 |
+
### Optional Arguments
|
| 182 |
+
|
| 183 |
+
| Argument | Default | Description |
|
| 184 |
+
|----------|---------|-------------|
|
| 185 |
+
| `--batch_size` | 64 | Batch size for training |
|
| 186 |
+
| `--epochs` | 50 | Number of training epochs |
|
| 187 |
+
| `--lr` | 0.001 | Learning rate |
|
| 188 |
+
| `--step_size` | 10 | Learning rate scheduler step size |
|
| 189 |
+
| `--save_dir` | ./checkpoints | Directory to save model checkpoints |
|
| 190 |
+
| `--model_name` | best_model.pth | Filename for saved model |
|
| 191 |
+
| `--seed` | 42 | Random seed for reproducibility |
|
| 192 |
+
| `--num_workers` | 4 | Number of data loading workers |
|
| 193 |
+
|
| 194 |
+
---
|
| 195 |
+
|
| 196 |
+
## π§ Advanced Usage Examples
|
| 197 |
+
|
| 198 |
+
### Custom Save Directory and Model Name
|
| 199 |
+
```bash
|
| 200 |
+
python main.py \
|
| 201 |
+
--dataset levir \
|
| 202 |
+
--train_path /data/LEVIR-CD/train \
|
| 203 |
+
--test_path /data/LEVIR-CD/test \
|
| 204 |
+
--val_path /data/LEVIR-CD/val \
|
| 205 |
+
--save_dir ./experiments/levir_exp1 \
|
| 206 |
+
--model_name levir_model.pth \
|
| 207 |
+
--epochs 100
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
### Different Learning Rate Schedule
|
| 211 |
+
```bash
|
| 212 |
+
python main.py \
|
| 213 |
+
--dataset sysu \
|
| 214 |
+
--train_path /data/SYSU-CD/train \
|
| 215 |
+
--test_path /data/SYSU-CD/test \
|
| 216 |
+
--val_path /data/SYSU-CD/val \
|
| 217 |
+
--lr 0.0005 \
|
| 218 |
+
--step_size 20 \
|
| 219 |
+
--epochs 150
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
### Smaller Batch Size (for limited GPU memory)
|
| 223 |
+
```bash
|
| 224 |
+
python main.py \
|
| 225 |
+
--dataset levir \
|
| 226 |
+
--train_path /data/train \
|
| 227 |
+
--test_path /data/test \
|
| 228 |
+
--val_path /data/val \
|
| 229 |
+
--batch_size 16 \
|
| 230 |
+
--num_workers 2
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
---
|
| 234 |
+
|
| 235 |
+
## π€ Output
|
| 236 |
+
|
| 237 |
+
During training, the script will:
|
| 238 |
+
- Display training loss for each batch
|
| 239 |
+
- Show validation metrics (IoU, confusion matrix) after each epoch
|
| 240 |
+
- Save the best model based on validation IoU
|
| 241 |
+
- Display learning rate and epoch time
|
| 242 |
+
|
| 243 |
+
### Model Checkpoint
|
| 244 |
+
|
| 245 |
+
The best model is automatically saved to:
|
| 246 |
+
```
|
| 247 |
+
{save_dir}/{model_name}
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
Default: `./checkpoints/best_model.pth`
|
| 251 |
+
|
| 252 |
+
---
|
| 253 |
+
|
| 254 |
+
## π Troubleshooting
|
| 255 |
+
|
| 256 |
+
### Paths with Spaces
|
| 257 |
+
|
| 258 |
+
If your paths contain spaces, wrap them in quotes:
|
| 259 |
+
```bash
|
| 260 |
+
python main.py \
|
| 261 |
+
--dataset levir \
|
| 262 |
+
--train_path "/path/with spaces/train" \
|
| 263 |
+
--test_path "/path/with spaces/test" \
|
| 264 |
+
--val_path "/path/with spaces/val"
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
### CUDA Out of Memory
|
| 268 |
+
|
| 269 |
+
Reduce batch size:
|
| 270 |
+
```bash
|
| 271 |
+
python main.py --dataset levir ... --batch_size 16
|
| 272 |
+
```
|
| 273 |
+
|
| 274 |
+
### Missing WHU Text Files
|
| 275 |
+
|
| 276 |
+
For WHU dataset, ensure all three text files are provided:
|
| 277 |
+
```bash
|
| 278 |
+
python main.py \
|
| 279 |
+
--dataset whu \
|
| 280 |
+
--train_path /data/WHU-CD \
|
| 281 |
+
--train_txt train_list.txt \
|
| 282 |
+
--test_txt test_list.txt \
|
| 283 |
+
--val_txt val_list.txt
|
| 284 |
+
```
|
| 285 |
+
|
| 286 |
+
---
|
| 287 |
+
|
| 288 |
+
## π‘ Getting Help
|
| 289 |
+
|
| 290 |
+
View all available arguments:
|
| 291 |
+
```bash
|
| 292 |
+
python main.py --help
|
| 293 |
+
```
|
| 294 |
+
|
| 295 |
+
---
|
| 296 |
+
|
| 297 |
+
## π§ Contact
|
| 298 |
+
|
| 299 |
+
If you have any questions, please contact Elman Ghazaei at elman.ghazaei@sabanciuniv.edu
|
| 300 |
+
|
| 301 |
+
---
|
| 302 |
+
|
| 303 |
+
## Qualitative Analysis:
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
<p align="center">
|
| 310 |
+
<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" />
|
| 311 |
+
</p>
|
| 312 |
+
|
| 313 |
+
---
|
| 314 |
+
# Results
|
| 315 |
+
|
| 316 |
+
<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" />
|
| 317 |
|
|
|
|
| 318 |
|
|
|
|
| 319 |
|