DOFA Embedder¶
geoembed.models.dofa
¶
DOFA (Dynamic One-For-All) embedding model implementation.
DofaEmbedder(weights='DOFA_MAE', wavelengths=None, mixed_precision=True, **kwargs)
¶
Bases: Embedder
Implementation of the DOFA (Dynamic One-For-All) architecture.
DOFA is a Vision Transformer (ViT) pre-trained on massive amounts of satellite data. It supports dynamic wavelength selection, allowing it to adapt to different sensor configurations (Sentinel-2, Landsat, aerial RGB, etc.).
Default wavelengths are for RGB aerial imagery: - Red: 0.640 um - Green: 0.538 um - Blue: 0.467 um
Output: 768-dimensional embedding per chip (ViT-Base backbone).
Initialise the DOFA model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
str | Weights
|
Name of the weights to load (e.g. "DOFA_MAE") or Weights object. |
'DOFA_MAE'
|
wavelengths
|
list[float] | None
|
Sensor wavelengths in micrometres. Defaults to RGB [0.640, 0.538, 0.467]. |
None
|
mixed_precision
|
bool
|
If True, uses FP16/BF16 during inference for speed and lower VRAM. |
True
|
**kwargs
|
Any
|
Additional arguments passed to the base Embedder (e.g., device). |
{}
|
Source code in src/geoembed/models/dofa.py
embed(batch)
¶
Generate DOFA embeddings for a batch of images.
Handles GPU transfer, float conversion, AMP context, and wavelength injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Tensor
|
Input tensor of shape (B, 3, 224, 224). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Embedding tensor of shape (B, 768). |