SAR Oil-Spill Classifier
A 3-way classifier (oil / lookalike / no_oil) for Sentinel-1 SAR imagery, built as the detection stage of a larger pipeline whose next stage segments confirmed oil scenes to estimate spill area.
Research/hackathon prototype, not a certified detector. Read the Limitations section before using this for anything beyond experimentation.
Input format — read this before loading any of your own data
This model does not take RGB photos. It expects 2-channel Sentinel-1 dual-polarization SAR backscatter (VH, VV), in dB, preprocessed exactly as follows:
- Per-scene percentile clip (1st-99th percentile) of each band to compress
dynamic range, then scaled to
uint8(0-255). - Resized to 512x512.
- Normalized as
(pixel/255 - 0.5) / 0.5. - Channel order: index 0 = VH, index 1 = VV.
model.py's preprocess() function does steps 3-4 for you, given an already
512x512, already-percentile-normalized uint8 array (step 1-2). If you're
starting from a raw Sentinel-1 product, you need to reproduce steps 1-2
yourself first — feeding this model raw dB floats, a 3-channel image, or an
unnormalized array will not error, it will just produce meaningless output.
Output format
3 logits, softmax to get probabilities, in this exact, fixed order:
CLASS_NAMES = ["no_oil", "lookalike", "oil"]
argmax gives the predicted index into that list. This order is fixed by
how the model was trained — do not assume alphabetical or any other order.
Quickstart
pip install torch torchvision safetensors numpy
python inference_example.py
Runs the model on the bundled sample_tile.npz (a real held-out test image,
true label oil) and prints the prediction — confirms your environment can
load and run the model before you point it at your own data.
Minimal manual usage:
import numpy as np
import torch
from safetensors.torch import load_file
from model import build_classifier, preprocess, CLASS_NAMES
model = build_classifier()
model.load_state_dict(load_file("model.safetensors"))
model.eval()
image = np.load("your_tile.npz")["image"] # (512, 512, 2) uint8, VH/VV, percentile-normalized
with torch.no_grad():
probs = torch.softmax(model(preprocess(image)), dim=1).squeeze(0)
print(CLASS_NAMES[probs.argmax().item()], probs.tolist())
Architecture
ResNet18 (ImageNet-pretrained backbone) with its first convolution replaced
to accept 2 input channels instead of 3 — initialized by averaging the
pretrained 3-channel weights across the 2 output channels, so the rest of
the pretrained network starts from a reasonable warm state despite the input
change. See model.py for the exact, minimal reconstruction code required
to load model.safetensors — the weights are a bare state_dict, not a
pickled model object.
Trained with torch==2.14.0, torchvision==0.29.0.
Training data
Sentinel-1 IW GRD scenes (dual-pol, calibrated, terrain-corrected, dB), 2048x2048 native resolution, resized to 512x512 for this classifier. Class label = source dataset folder (oil / lookalike / no_oil) — a whole-scene label, not a pixel-level annotation. Trained on 2,570 scenes, evaluated on a held-out 450-scene split (150 per class, untouched during training).
Metrics (test set, n=450, balanced 150/150/150)
Accuracy: 86.89%
| class | recall | precision |
|---|---|---|
| no_oil | 94.7% | 74.7% |
| lookalike | 65.3% | 83.8% |
| oil | 91.3% | 95.8% |
Confusion matrix (rows = true, columns = predicted; note this specific matrix was captured from the run's final epoch rather than reloaded from the best checkpoint, so exact cell counts may differ slightly from the 86.89% headline number — the pattern below is representative regardless):
no_oil lookalike oil
no_oil 142 8 0
lookalike 46 98 6
oil 2 11 137
Limitations
lookalikeis the weak class. The model separatesoilandno_oilcleanly; most errors are lookalike scenes misread as plainno_oil. This mirrors the genuine difficulty of the underlying problem — look-alike SAR phenomena (low-wind zones, biogenic slicks, current shear) exist specifically because they resemble one of the other two classes.- Resizing to 512x512 (from a 2048x2048 native scene) may wash out subtle, spatially small look-alike texture — a likely contributor to the recall gap above.
- Whole-scene labels, not pixel-level ground truth — this model tells you whether a scene contains oil, not where. Pixel-level extent comes from a separate segmentation model downstream.
- Evaluated on one dataset's distribution and geography. Not validated against out-of-distribution regions, sensors, or acquisition conditions.
- Not evaluated for adversarial robustness, calibration, or fairness across any subgroup.
Intended use
Research and prototyping for oil-spill monitoring pipelines. Not intended, and not validated, for autonomous operational decision-making, regulatory reporting, or any use where a missed or false detection carries real-world consequences without human review.
License
Placeholder — set this before publishing. These weights were trained on
a Zenodo-hosted SAR oil-spill dataset; check that dataset's own license
before choosing how to release the weights, since a restrictive source
license can carry through to a model trained on it. Update the license:
field in this file's YAML header once decided.