ftw-q
Agricultural field boundary segmentation from one year of quarterly Sentinel-2 cloudless mosaics. A U-Net with an EfficientNet-B3 encoder, trained on FTW-Q.
Files
| File | Description |
|---|---|
ftw-q-unet-efb3.pt | PyTorch state dict |
ftw-q-unet-efb3.onnx | ONNX (opset 18, fp32), dynamic batch, height and width |
Input and output
- Input:
(batch, 16, H, W)float32, with H and W multiples of 32. Channels are[B04, B03, B02, B08]for each ofQ1, Q2, Q3, Q4, in that order (channel4 * q + b), from the Copernicus Sentinel-2 Global Mosaics (int16, reflectance × 10000). - Preprocessing: divide the raw values by 3000, then upsample the 10 m pixels 4× with bilinear interpolation to 2.5 m. A 1536 × 1536 input covers 384 × 384 pixels at 10 m.
- Output:
logits,(batch, 3, H, W)at 2.5 m. Classes: 0 background, 1 field, 2 field boundary.
The model was trained on 512 × 512 crops, but it predicts better with more context. On large
images, run 1536 × 1536 patches at 50% overlap and blend them with a Hann window. With 512
patches it scores fields only near each patch centre in low-contrast cropland, such as the
Sahel. The ONNX file accepted only 512 × 512 before 2026-10-26; that export is revision
f5aecca0 of this repository.
Usage
import numpy as np
import onnxruntime as ort
import torch
import torch.nn.functional as F
x = torch.from_numpy(stack.astype(np.float32) / 3000)[None] # stack: (16, 384, 384) at 10 m
x = F.interpolate(x, scale_factor=4, mode="bilinear", align_corners=False)
sess = ort.InferenceSession("ftw-q-unet-efb3.onnx")
logits = sess.run(None, {"input": x.numpy()})[0]
PyTorch, with segmentation-models-pytorch 0.5.0:
import segmentation_models_pytorch as smp
import torch
model = smp.Unet(encoder_name="efficientnet-b3", encoder_weights=None, in_channels=16, classes=3)
model.load_state_dict(torch.load("ftw-q-unet-efb3.pt", map_location="cpu"))
model.eval()
Training
- Data: the FTW-Q train split; the checkpoint with the best validation polygon F1 is kept.
- Initialization: ImageNet encoder weights.
- Optimization: 35 epochs, batch size 16, AdamW, learning rate 1e-3 with cosine decay, cross-entropy + Dice loss, bf16 mixed precision.
- Augmentation: random 512 × 512 crops; horizontal and vertical flips, rotation within
±90° and sharpness (each p = 0.5); a per-sample normalization divisor drawn from
U(1500, 4500) in place of 3000; per-band gamma U(0.8, 1.2) (p = 0.3) and per-band affine
a·x + bwith a ~ U(0.9, 1.1), b ~ U(−0.1, 0.1) (p = 0.5); with p = 0.4, one quarter is replaced by a copy of another.
Evaluation
FTW-Q test split, 7,817 chips. Field polygons are extracted from the argmax field class, polygons under 1,000 m² are dropped, and each is matched to a label polygon at IoU > 0.5. Scores are averaged over countries, excluding Kenya and Portugal.
| Object F1 | Precision | Recall |
|---|---|---|
| 0.526 | 0.601 | 0.475 |
License
CC-BY-4.0.