Skip to content

fix: OlmoEarth backbone forward pass to match olmoearth_pretrain API - #1202

Open
whatnick wants to merge 2 commits into
torchgeo:mainfrom
whatnick:feature/olmoearth-backbone
Open

fix: OlmoEarth backbone forward pass to match olmoearth_pretrain API#1202
whatnick wants to merge 2 commits into
torchgeo:mainfrom
whatnick:feature/olmoearth-backbone

Conversation

@whatnick

Copy link
Copy Markdown

Summary

Fixes the OlmoEarth backbone integration to work correctly with the olmoearth-pretrain package API.

Changes

  • Modality name: Use sentinel2_l2a (matching MaskedOlmoEarthSample NamedTuple fields) instead of the invalid sentinel2
  • Input format: Pass raw pixels in [B, H, W, T, C] format — the encoder handles patchification internally
  • Mask format: Use pixel-resolution mask [B, H, W, T, num_band_sets] with correct band set count (3 for S2 L2A)
  • Timestamps: Use [B, T, 3] long tensors with [day, month, year] (not float zeros)
  • Embed dim: Read from encoder.embedding_size at runtime instead of relying on potentially stale config values
  • Feature extraction: Use per-modality spatial tokens from tokens_and_masks (averaged over T and band_sets), not the global project_aggregated vector
  • Config fix: Corrected Nano embed_dim from 64 → 128

Testing

All 8 tests in tests/test_olmoearth.py pass (~2 min on CPU, no GPU required):

  • Registration tests (2)
  • Instantiation without weights (1)
  • Forward pass shape verification (1)
  • Multiple input sizes (1)
  • Registry-based creation (1)
  • Invalid variant error (1)
  • Import guard (1)

whatnick added 2 commits June 29, 2026 23:06
Add integration for OlmoEarth (Allen AI) foundation models as
registered backbones in the TerraTorch backbone registry.

- Register 11 model variants: v1 (nano/tiny/base/large),
  v1.1 (nano/tiny/base), v1.2 (nano/tiny/small/base)
- OlmoEarthBackbone wrapper adapts the encoder's token output
  to spatial feature maps (B, D, H', W') for TerraTorch decoders
- Added as optional dependency: pip install terratorch[olmoearth]
- Tests with skipif guard for environments without olmoearth-pretrain

References:
- GitHub: https://github.com/allenai/olmoearth_pretrain
- Paper: https://arxiv.org/abs/2511.13655
- Issue: torchgeo#1201

Signed-off-by: Tisham Dhar <tisham.dhar@csiro.au>
- Use correct modality name 'sentinel2_l2a' (NamedTuple field name)
- Pass raw pixels in [B, H, W, T, C] format (encoder does patchification)
- Use pixel-resolution mask with correct num_band_sets dimension
- Use long dtype timestamps with [day, month, year] format
- Read embed_dim from encoder.embedding_size instead of hardcoded config
- Extract spatial features from tokens_and_masks (not project_aggregated)
- Fix Nano embed_dim from 64 to 128 in config and tests

Signed-off-by: Tisham Dhar <tisham.dhar@csiro.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant