deepcontrail-instance
Instance segmentation of contrails, part of DeepContrail: it splits a contrail segmentation map into individual contrails, one mask and one score each.
Status: alpha, like the rest of DeepContrail: the API may change between minor versions, and every change is listed in the changelog.
It needs only deepcontrail-core, numpy, scipy, pydantic and PyYAML (no torch) and never imports
deepcontrail.segmentation: any model's probability map works as input. Two optional extras:
[map] (pycocotools) to save detections as COCO results, and [scores] (scikit-learn) to train a
score model.
pip install deepcontrail-instance # the base package
pip install "deepcontrail-instance[map,scores]" # with both extras
Usage
import numpy as np
from deepcontrail.instance import detect_instances_from_probabilities
probs = np.load("scene_probs.npy") # (H, W) probabilities in [0, 1]
masks, scores = detect_instances_from_probabilities(probs)
# masks: one boolean (H, W) mask per contrail; scores: in [0, 1], for ranking
The scores rank the detections; they are not probabilities. Without a score model, a score is the contrail's straightness × tanh(size / saturation) × its mean probability; with one (see "Learned scores" below), it is the predicted overlap (mean best IoU) with the annotators' contrails. Every detection is returned, without a score cut: to trade recall for precision, drop the low scores, with a cut chosen on your own validation scenes.
The pipeline thresholds the map (at 0.465), splits the mask into straight contrails with a
Mannstein-style detection, grows each contrail by one pixel into neighbours with probability above
0.371 (annotators draw contrails wider than the thresholded mask), and weights each score by the
contrail's mean probability. Its settings live in InstancePipelineConfig; the defaults equal
configs/instance_pipeline.yaml, and
InstancePipelineConfig.consensus() equals
configs/instance_pipeline_consensus.yaml, for when
only contrails agreed by most annotators matter. detect_instances(binary_mask) runs plain
Mannstein on any binary mask (settings: MannsteinConfig, whose defaults are the pipeline's;
configs/mannstein_annotator_masks.yaml holds the
settings for annotators' own masks, the same as InstancePipelineConfig.consensus().mannstein).
Mannstein's oriented line filter (MannsteinConfig(line_filter=True)) is off in the shipped
settings: on these masks it kept every pixel and took most of the run time.
Input. A (H, W) map of probabilities in [0, 1] (after the sigmoid, not logits), on the same
pixel grid as the masks it is compared with. NaN or infinite values are rejected. A binary mask
also works as input: probability weighting then changes nothing, but growth can still add mask
pixels that no contrail took. For a plain binary mask, detect_instances(mask) runs the
Mannstein-style step alone.
Known limits.
- All settings are in pixels, tuned on GOES-16 / OpenContrails scenes (about 2 km per pixel, contrails 1–3 px wide). Other resolutions need re-tuning.
- The cut (0.465) and the growth (into p > 0.371) were tuned on the validation predictions of DeepContrail's earlier reference model (UPerNet + CAFormer-B36, trained on soft labels). They carry over to the current Unet++ model, which scores higher with them on every measure below. For another kind of model, re-tune the pipeline on its predictions for scenes it never trained on; tuning needs instance annotations.
- Two contrails that cross at less than about 25° often come out as one, depending on their width and direction. Touching, nearly parallel contrails also merge.
- The COCO mAP keeps at most 100 detections per sample (a warning says when a sample has more).
With a pretrained DeepContrail model
A pretrained bundle of deepcontrail-segmentation may carry the instance step tuned for its
model: instance_pipeline.yaml and a score_model.json trained on that model's predictions.
load_instance_step reads them from the bundle's folder (the defaults when they are absent) and
refuses a score model made with the other test-time-augmentation setting. On the five sample
scenes of the root README's quickstart (needs deepcontrail-segmentation too):
import numpy as np
from huggingface_hub import snapshot_download
from deepcontrail.core import false_color_from_spectral, read_band_manifest
from deepcontrail.instance import load_instance_step, to_coco_results
from deepcontrail.segmentation import load_pretrained, predict
root = snapshot_download("eurocontrol-asu/deepcontrail-samples", repo_type="dataset")
model = load_pretrained("eurocontrol-asu/deepcontrail-segmentation", revision="v0.1.0")
bands = np.load(f"{root}/spectral_bands/test/1801360214472457069.npy")
composite = false_color_from_spectral(bands, model.config.false_color, read_band_manifest(root))
probabilities = predict(model, composite, tta=model.config.tta)
step = load_instance_step(model.directory, tta=model.config.tta)
masks, scores = step(probabilities)
results = to_coco_results(masks, scores, image_id="1801360214472457069") # JSON-ready, needs [map]
A score model records what it was trained on (ScoreModel.trained_on: semantic model, TTA,
scene size, scikit-learn and package versions); the pipeline refuses it on scenes of another size,
since its features are in pixels. save_instance_step writes the two files into a bundle folder.
Both files carry a format_version. Any new field, or any change of meaning, raises it, so an
older deepcontrail-instance refuses a newer file with a message to upgrade instead of misreading
it. Unknown fields are always an error, so a typo is never ignored.
Annotations and results
The annotation tools need only instance_masks: each annotator's mask, the agreement map, the
consensus mask and the consensus contrails (drawn by more than half of the annotators) are derived
from it by deepcontrail.instance.labels, for any number of annotators, one included.
Instance annotations use the instance_masks/<split>/<id>.npy format of the
DeepContrail dataset format: an (N, H, W, A) int8 array (1 = pixel of contrail n
drawn by annotator a, 0 = not, -1 = annotator a drew no contrail n; A = 1 for one annotator),
read with deepcontrail.core.readers.load_instance_masks. instance_masks_from_label_image and
instance_masks_from_annotators build it from a label image or from per-annotator masks.
to_coco_results(masks, scores, image_id) (needs [map]) saves detections as COCO results with
RLE masks, so overlapping contrails stay separate:
import json
from deepcontrail.instance import to_coco_results
json.dump(to_coco_results(masks, scores, image_id="scene_1"), open("instances.json", "w"))
Learned scores
A ScoreModel predicts, from 20 features of each detected contrail (size, shape, probabilities,
surroundings), how well it matches the annotated contrails, and that prediction replaces its
score; the masks do not change. The features depend on the semantic model, so a score model is
valid only for the semantic model and pipeline settings it was trained with, and refuses other
pipeline settings. Training (ScoreModel.fit, with training_data) needs [scores]; a saved
model is plain JSON and predicts with numpy only:
from deepcontrail.instance import (
InstancePipelineConfig,
ScoreModel,
detect_instances_from_probabilities,
)
config = InstancePipelineConfig() # the shipped defaults, = configs/instance_pipeline.yaml
model = ScoreModel.from_json("score_model.json") # from a bundle, or train_score_model.py
masks, scores = detect_instances_from_probabilities(probs, config, score_model=model)
Evaluation
deepcontrail.instance.metrics.evaluate_annotator_samples (needs [map]) scores detections
against each annotator's contrails as a separate ground truth: one sample per (scene, annotator)
pair. The headline is the COCO segmentation mAP averaged over IoU 0.25–0.75, pooled over all
samples; precision, recall and F1 are at IoU 0.5. Samples where the annotator drew no contrail are
skipped by default; include_empty=True keeps them, so every detection on them counts as false,
which is closer to real use.
Results on the OpenContrails 2025 test split (1,879 scenes, 2,700 annotator samples with at least one contrail), from the probabilities of DeepContrail's reference semantic model (Unet++ + CAFormer-B36, D4 TTA); the learned scores were trained on its validation predictions. Every setting was chosen on validation scenes; the test split was only scored. The consensus columns score each scene once against its consensus contrails.
| Settings | mAP | mAP, with empty | Precision (with empty) | Recall | F1 (with empty) | Consensus mAP | Consensus mAP, all scenes |
|---|---|---|---|---|---|---|---|
configs/instance_pipeline.yaml (defaults) |
0.273 | 0.268 | 0.532 (0.504) | 0.387 | 0.448 (0.438) | 0.424 | 0.417 |
configs/instance_pipeline_consensus.yaml (no growth) |
0.252 | 0.248 | 0.510 (0.485) | 0.350 | 0.415 (0.407) | 0.446 | 0.439 |
| defaults + learned scores | 0.280 | 0.273 | 0.532 (0.504) | 0.387 | 0.448 (0.438) | 0.435 | 0.424 |
| consensus settings + learned scores | 0.258 | 0.253 | 0.510 (0.485) | 0.350 | 0.415 (0.407) | 0.459 | 0.450 |
The model bundle on the Hugging Face Hub carries the defaults with their learned scores (third
row). The consensus settings are InstancePipelineConfig.consensus() (second row); their learned
scores (fourth row) are not published.
On each annotator's own mask instead of a prediction, the instance step alone reaches mAP 0.921
(configs/mannstein_annotator_masks.yaml). Most errors therefore come from the semantic step and
from contrail shape: the AP is 0.50 at IoU 0.25 but 0.02 at IoU 0.75. Annotators also disagree
strongly on individual contrails: one annotator scored against the others reaches F1 ≈ 0.35 on
validation scenes.
Scripts (repository only)
Command-line tools in scripts/, run from the repository root. They read only
instance_masks/<split>/ from a dataset, plus one <id>.npy probability map per scene for a
semantic model's predictions.
evaluate_instances.py: the evaluation above, on predictions (--pred-dir), on the consensus mask (--use-gt-semantic) or on each annotator's mask (--use-annotator-semantic);--score-model,--include-empty,--consensus-gt.train_score_model.py: trains aScoreModel(needs[scores]).optimize_pipeline.pyandoptimize_mannstein.py: Optuna searches of the pipeline and Mannstein settings (optuna is in the repository'sexperimentsgroup); they never read the test split.
Tuning for your own semantic model: predict the scenes it never trained on (for example its
validation split), search the pipeline settings on them (optimize_pipeline.py), train a score
model on the same predictions (train_score_model.py), then score the test split once
(evaluate_instances.py).
uv run python packages/instance/scripts/train_score_model.py --root <dataset_root> \
--pred-dir <validation probability maps> \
--pipeline-config packages/instance/configs/instance_pipeline.yaml --output-dir <dir>
References and acknowledgements
The line filter and the size, length and straightness tests follow Mannstein, Meyer & Wendling (1999), "Operational detection of contrails from NOAA-AVHRR data", International Journal of Remote Sensing 20(8), 1641–1660, doi:10.1080/014311699212650.
The direction-following region growing and the related shape tests build on ideas from a student project (PIE) at ISAE-SUPAERO, carried out with EUROCONTROL.
Metadata
Release files for deepcontrail-instance 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deepcontrail_instance-0.3.0.tar.gz | 48.6 kB | With provenance | Details for deepcontrail_instance-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deepcontrail_instance-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for deepcontrail_instance-0.3.0-py3-none-any.whl |
Total release size: 101.8 kB
Release files / deepcontrail_instance-0.3.0.tar.gz
| Download URL | deepcontrail_instance-0.3.0.tar.gz |
|---|---|
| Size | 48.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a17a41cc4fcdf49deeae6b1afdc28189f16a749b3d6d6b1e69d1d17684e71f60
|
|
BLAKE2b-256 checksum How to use checksums |
9c2c036bbb30f6f32eb4e251f0fc772686c154697d87b6261e5f7c495974e981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / deepcontrail_instance-0.3.0-py3-none-any.whl
| Download URL | deepcontrail_instance-0.3.0-py3-none-any.whl |
|---|---|
| Size | 53.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f233be9248090b7bd0559491aafa42681fb3122d900f6cac8121de8c47af4c6f
|
|
BLAKE2b-256 checksum How to use checksums |
1e03170a1eeefbc9e10470d405e3fe65fbf3ba6fcae183296865f84072aa477f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for deepcontrail-instance 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for deepcontrail_instance-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.