Skip to main content

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: preview. The API may still change in the next releases.

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: confidence in [0, 1]

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).

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 crossing at a small angle come out as one: at 10° always, at 20° with the consensus settings. 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:

from deepcontrail.instance import load_instance_step, to_coco_results
from deepcontrail.segmentation import load_pretrained, predict

model = load_pretrained("eurocontrol-asu/deepcontrail-segmentation")
step = load_instance_step(model.directory, tta=model.config.tta)
probabilities = predict(model, composite, tta=model.config.tta)
masks, scores = step(probabilities)
results = to_coco_results(masks, scores, image_id="scene_1")  # 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.

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

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 a ScoreModel (needs [scores]).
  • optimize_pipeline.py and optimize_mannstein.py: Optuna searches of the pipeline and Mannstein settings (optuna is in the repository's experiments group); 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.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deepcontrail-instance 0.2.0
File Size Uploaded Provenance Actions
deepcontrail_instance-0.2.0.tar.gz 46.5 kB With provenance Details for deepcontrail_instance-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deepcontrail-instance 0.2.0
File Interpreter ABI Platform Actions
deepcontrail_instance-0.2.0-py3-none-any.whl Python 3 none any Details for deepcontrail_instance-0.2.0-py3-none-any.whl

Total release size: 97.9 kB

Release files / deepcontrail_instance-0.2.0.tar.gz

Download URL deepcontrail_instance-0.2.0.tar.gz
Size 46.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ad82d2a439d55d8cb9a4823e3f05804d376529d16d63699a7ca886a8fc29dcd4
BLAKE2b-256 checksum
How to use checksums
6ecd15888524e8ac32766028150427ce52289a1133bc7571cc7437e894c2bf5d
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 13, 2026.

Transparency log

Release files / deepcontrail_instance-0.2.0-py3-none-any.whl

Download URL deepcontrail_instance-0.2.0-py3-none-any.whl
Size 51.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30e5ebc5835f2b0332c503b04b7f80e9e9c6f1fb4cf8d3300063de8499e1f325
BLAKE2b-256 checksum
How to use checksums
ac76901bb83938feac2ba282bbf40ddd1d2d91fb442fac8abd4277e7d4312dfc
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 13, 2026.

Transparency log

Security for deepcontrail-instance 0.2.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.

Select from 2 files

Attestation for deepcontrail_instance-0.2.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 13, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page