Skip to content
prithvi-kaizenPublic

About

Satellite methane-plume segmentation with TerraMind and PyTorch. Includes a live Streamlit demo, CLI, and local Flask API.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Terramind

Satellite methane-plume segmentation with a frozen geospatial foundation model, a local inference API, and an interactive dashboard.

Live demo: terramind-demo.streamlit.app

Terramind was developed as MethanePulse during a hackathon. It takes a Sentinel-2 GeoTIFF, predicts a plume mask and a relative plume-size class, and exports a georeferenced mask plus a JSON alert. The model uses TerraMind-1.0-small through TerraTorch; the foundation model itself was developed by IBM, ESA, and Forschungszentrum Jülich.

Try the live demo

  1. Open terramind-demo.streamlit.app.
  2. Keep Sample tile selected and click Run Inference.
  3. Inspect the red plume overlay, coverage statistics, and alert JSON. Alert Log shows your session's predictions; Model Card shows the experiment configuration.

The hosted demo runs real CPU inference with the included checkpoint. No local installation, training dataset, or API key is required. The first prediction can take longer while the model libraries initialise. To use your own input, choose Upload tile and supply a 13-band, 512×512 GeoTIFF in the documented band order, up to 32 MiB. See DATA.md for the input conventions.

Hosted sample inference showing the input tile, predicted plume overlay, and coverage statistics

Screenshot of a verified sample prediction on the hosted app. The displayed severity is a mask-area proxy, not an emission-rate measurement.

What you can run

  • A Streamlit dashboard with sample-tile inference, validated uploads, individual candidate inspection, artifact downloads, an alert log, and a model-card view.
  • A command-line inference script exporting raw/filtered masks, probabilities, candidate GeoJSON, and a schema 2.0 alert.
  • A Flask POST /predict endpoint for local multipart uploads.
  • Five research notebooks covering data exploration, a spectral baseline, TinyUNet, and the TerraMind model.
  • The trained checkpoint, sample input, saved sample outputs, and experiment logs.

This is a research prototype. Severity is derived from mask area, not a measured methane emission rate. Satellite acquisition gaps, false positives, and performance on real plumes remain open problems. Read the model card before interpreting predictions. A fixed real-scene stress test evaluated 63 plume scenes and 63 clean references: pixel IoU was 0.0174, and 62 of 63 references triggered false positives. The current checkpoint is unsuitable for operational leak detection. See the external evaluation protocol and results.

Run locally

Use Python 3.12. The included checkpoint is approximately 85 MiB, so the initial clone is larger than a typical Python project.

git clone https://github.com/prithvi-kaizen/Terramind.git
cd Terramind
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python scripts/check_environment.py
python -m streamlit run app.py

Open localhost:8501, keep Sample tile selected, and click Run Inference. The included checkpoint supplies the complete encoder and head weights, so the maintained demo does not download model weights at runtime. The complete training dataset is unnecessary for this demo.

On Windows, activate with .venv\Scripts\activate. See SETUP.md for the API, notebook workflow, platform notes, and troubleshooting.

For hosting, use the Streamlit Community Cloud deployment guide and deployment/streamlit_app.py. Its Linux requirements select CPU-only PyTorch, and the dashboard runs inference in one process.

Command-line inference

python infer.py \
  --input sample_input/0___0_S2B_20240326T165849_R1000_nonorm_bands20m.tiff \
  --checkpoint terramind_methane_best.pt \
  --output outputs/demo \
  --threshold 0.5

The output directory contains <tile>_mask.tiff and <tile>_alert.json. Each request writes into a unique subdirectory; use the returned artifact paths. The runtime selects Apple MPS, CUDA, or CPU based on availability.

Local API

python endpoint.py

In another terminal:

curl -X POST http://127.0.0.1:5001/predict \
  -F 'file=@sample_input/0___0_S2B_20240326T165849_R1000_nonorm_bands20m.tiff' \
  -F 'threshold=0.5'

The endpoint returns the alert JSON. This server is intended for local development; deployment hardening is part of the implementation plan.

How the model works

flowchart LR
    A[13-band Sentinel-2 GeoTIFF] --> B[Select B11 and B12]
    B --> C[Percentile normalisation and resize to 224 x 224]
    C --> D[Frozen TerraMind-small encoder]
    D --> E[Transposed-convolution segmentation decoder]
    D --> F[Mean-pooled embeddings and severity MLP]
    E --> G[512 x 512 binary plume mask]
    F --> H[LOW / MEDIUM / HIGH area class]
    G --> I[GeoTIFF and JSON alert]
    H --> I
Loading

The encoder produces patch embeddings. The segmentation branch has four transposed convolutions followed by a 1×1 convolution and interpolation. The severity branch uses mean-pooled patch embeddings, not a CLS token. Saved notebook output records 616,388 trainable head parameters; encoder weights remain frozen.

Current checkpoint evaluation

The existing checkpoint was evaluated at threshold 0.5 without retraining or threshold tuning.

Evaluation Scored / available Pixel IoU Pixel F1
Published synthetic train split 700 / 700 0.4797 0.6483
Published synthetic validation split 104 / 104 0.4702 0.6397
Published synthetic test split 195 / 196 0.4291 0.6005
Real-scene stress test, including clean references 126 / 128 0.0174 0.0343

All 1,000 synthetic inputs were audited; one test image lacked a matching label. The real cohort rejected one pair with invalid pixels. Published synthetic splits share locations and plume identifiers, and the checkpoint's training-run mapping is unknown. These scores do not establish independent geographic generalisation. On real clean references, 62 of 63 scenes triggered false positives. Read the protocol, exclusions, raw results, and interpretation.

Recorded experiments

These are saved experiment records, not independently reproduced benchmarks. The notebooks record a custom location-based split with 619 training tiles and 185 validation tiles. The published dataset's original split is different.

Experiment Recorded IoU Recorded F1 Evidence and interpretation
SWIR local-anomaly baseline 0.1210 0.2080 Saved metrics; averages per tile; threshold selected on validation data
TinyUNet 0.4897 0.6575 Saved metrics; global pixel aggregation; checkpoint absent
TerraMind notebook run 0.3298 Not recorded Notebook; averages batch IoU; best epoch 8
Separate TerraMind log 0.3257 0.5110 at best-IoU epoch Training log; best IoU at epoch 6; checkpoint association unverified

The aggregation rules differ, so these values do not establish a controlled comparison or a generalisation advantage. The separate log records severity accuracy as zero throughout; the notebook's severity accuracy at its best-IoU epoch is 0.395. Resolving this discrepancy is a first implementation milestone.

View the original TinyUNet qualitative results

Original notebook figure showing SWIR imagery, ground truth, probability maps, and TinyUNet predictions

Extracted unchanged from the saved output of notebooks/TinyUNet.ipynb. These are historical TinyUNet examples, including a missed plume, rather than newly executed TerraMind predictions.

Data and repository layout

The project uses GeoCH4PlumeNet, which contains simulated plumes inserted into Sentinel-2 imagery. Full training data is external; the sample tile and checkpoint are included here. See DATA.md for download and directory instructions.

app.py                       Streamlit dashboard
infer.py                     CLI and shared model inference
endpoint.py                  Local Flask endpoint
src/alert_packet.py          Original notebook alert helper
notebooks/                   Research notebooks
sample_input/                Included Sentinel-2 sample
results/                     Saved sample mask and alert
terramind_methane_best.pt     Trained checkpoint
deployment/                  Cloud entrypoint and CPU-only requirements
docs/                        Setup, model card, data guide, plan, logs
scripts/                     Environment and repository checks
tests/                       Runtime validation tests
.github/                     CI and contribution templates

Development

python -m pip install -r requirements-dev.txt
python scripts/validate_repository.py
python -m pytest

The CI workflow has two jobs: validate checks notebook structure, artifact hashes, documentation links, and 100 runtime tests; cloud-smoke installs the complete Linux CPU environment and runs real sample inference, dashboard checks and frozen-feature/gradient/review smoke checks with model downloads disabled. See validation evidence and GitHub Actions. These checks do not reproduce research training or establish model quality. Read CONTRIBUTING.md before changing data processing or metrics.

The Phase 1 guide covers model reuse, CPU benchmarking, evaluation manifests, and output retention. Phase 1 software is deployed; external evaluation evidence is documented in the public-data report.

Candidate review and exports

Phase 2 separates four-connected foreground regions into candidates with geodesic area, geometry, probability summaries and review flags. It uses the same model pass. Raw predictions remain unchanged; all heuristic removal rules are off by default. In Streamlit, inspect Plume candidates and expand Download prediction artifacts for mask/probability GeoTIFFs, GeoJSON and JSON. An advanced setting enables explicit experimental filtering.

The validation pilot did not justify promoting any removal rule: reduced false alarms came with excessive recall loss. See the Phase 2 completion report and deployment evidence, guide and migration notes, validation report, and CPU benchmark. Phase 2 improves inspection and export; it does not solve poor real-scene model transfer.

Next steps

The public demo and Linux inference smoke check are available. The three-phase implementation plan defines compute limits and acceptance checks. Phases 1 and 2 are implemented. Phase 3 research tooling adds frozen-feature caches, bounded decoder training, optional flip review and up to three-date corroboration. Reviewed training data and real aligned dates are still required for scientific experiments; no new checkpoint or accuracy improvement is claimed. See the Phase 3 report. Physical emission estimates and embedded deployment remain later research work.

Attribution and licensing

Foundation model: TerraMind-1.0-small model card. Framework: TerraTorch.

The project has no project-level license file. No new license is assigned to the code, checkpoint, or data in this setup. See PROVENANCE.md for artifact hashes and the remaining licensing decision.

About

Satellite methane-plume segmentation with TerraMind and PyTorch. Includes a live Streamlit demo, CLI, and local Flask API.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages