ftw module¶
Utilities for downloading and preparing the Fields of The World (FTW) dataset.
The Fields of The World (FTW) dataset is a large-scale benchmark for agricultural field boundary instance segmentation. It contains Sentinel-2 imagery (4 bands: Red, Green, Blue, NIR at 10 m resolution) paired with instance segmentation masks across 25 countries.
Reference
Kerner et al., "Fields of The World: A Machine Learning Benchmark Dataset For Global Agricultural Field Boundary Delineation", 2024. https://fieldsofthe.world/
display_ftw_samples(data_dir, country='luxembourg', num_samples=4, split='train', window='window_a', clip_value=3000, figsize=None, cmap='tab20', save_path=None)
¶
Display FTW image-mask pairs from the raw dataset.
Shows Sentinel-2 RGB images alongside their corresponding instance segmentation masks for visual inspection of the training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
str
|
Path to the root FTW data directory (containing country
subdirectories as downloaded by |
required |
country
|
str
|
Country subset to display. Defaults to "luxembourg". |
'luxembourg'
|
num_samples
|
int
|
Number of image-mask pairs to display. Defaults to 4. |
4
|
split
|
str
|
Dataset split to sample from ("train", "val", or "test"). Defaults to "train". |
'train'
|
window
|
str
|
Which temporal acquisition to display. The FTW dataset
provides two Sentinel-2 images per chip from different dates
( |
'window_a'
|
clip_value
|
int
|
Upper bound for Sentinel-2 reflectance used for RGB visualization. Defaults to 3000. |
3000
|
figsize
|
Optional[Tuple[int, int]]
|
Figure size as (width, height) in inches. If None,
auto-calculated based on |
None
|
cmap
|
str
|
Colormap for instance mask display. Defaults to "tab20". |
'tab20'
|
save_path
|
Optional[str]
|
If provided, save figure to this path instead of displaying. Defaults to None. |
None
|
Example
import geoai geoai.download_ftw(countries=["luxembourg"]) geoai.display_ftw_samples("ftw_data", country="luxembourg", num_samples=6)
Source code in geoai/ftw.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
download_ftw(countries=None, output_dir='ftw_data', overwrite=False)
¶
Download the Fields of The World (FTW) dataset for specified countries.
Downloads Sentinel-2 imagery and instance segmentation masks from the
FTW dataset hosted on Source Cooperative. Each country subset includes
256x256 pixel chips with 4-band (Red, Green, Blue, NIR) GeoTIFF images
captured at two different dates (window_a and window_b) and
corresponding instance mask GeoTIFFs. The two temporal windows allow
models to exploit seasonal vegetation differences for better field
boundary detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
countries
|
Optional[List[str]]
|
List of country names to download. If None, downloads
Luxembourg (smallest European subset). Use |
None
|
output_dir
|
str
|
Directory to save downloaded data. Defaults to "ftw_data". |
'ftw_data'
|
overwrite
|
bool
|
If True, re-download even if data already exists. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the output directory containing downloaded country subsets. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any country name is not in the list of available countries. |
Example
import geoai geoai.download_ftw(countries=["luxembourg"], output_dir="ftw_data") 'ftw_data'
Source code in geoai/ftw.py
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 | |
prepare_ftw(data_dir, country='luxembourg', output_dir=None, window='window_a', clip_value=3000, num_test=5, verbose=True)
¶
Prepare FTW data for training with geoai's instance segmentation pipeline.
Rescales Sentinel-2 reflectance images from 0-10000 to uint8 (0-255) and
organizes them into images/ and labels/ directories compatible with
geoai.train_instance_segmentation_model().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
str
|
Path to the root FTW data directory (containing country
subdirectories as downloaded by |
required |
country
|
str
|
Country subset to prepare. Defaults to "luxembourg". |
'luxembourg'
|
output_dir
|
Optional[str]
|
Directory to write prepared images and labels. If None,
defaults to |
None
|
window
|
str
|
Which temporal window to use for imagery. The FTW dataset
provides two Sentinel-2 acquisitions from different dates for
each chip so that seasonal vegetation differences can help
delineate field boundaries. |
'window_a'
|
clip_value
|
int
|
Upper bound for Sentinel-2 reflectance clipping before rescaling to 0-255. Defaults to 3000. |
3000
|
num_test
|
int
|
Number of test chips to prepare for inference. Set to 0 to skip test data preparation. Defaults to 5. |
5
|
verbose
|
bool
|
If True, print progress information. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with keys:
- |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the country directory or parquet metadata file is not found. |
Example
import geoai geoai.download_ftw(countries=["luxembourg"]) result = geoai.prepare_ftw("ftw_data", country="luxembourg") print(result["images_dir"], result["num_train"])
Source code in geoai/ftw.py
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 | |