RS-SSL Model Collection
Collection
3 items • Updated
How to use BiliSakura/DOFA-transformers with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("feature-extraction", model="BiliSakura/DOFA-transformers") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("BiliSakura/DOFA-transformers", dtype="auto")Self-contained HuggingFace model checkpoints for DOFA.
Each checkpoint subfolder ships remote code for model, processor, and pipeline loading with trust_remote_code=True.
Sentinel-2 9-band defaults (default_wavelengths, default_image_mean, default_image_std) are baked into config.json and preprocessor_config.json.
| Folder | Hidden size | Layers | Heads |
|---|---|---|---|
dofa-base-patch16-224/ |
768 | 12 | 12 |
dofa-large-patch16-224/ |
1024 | 24 | 16 |
Processors default to do_resize: false. Pass Sentinel-2 stacks at native (H, W, C); the processor rescales values (typically /255) without changing spatial size.
from transformers import pipeline
MODEL = "/path/to/DOFA-transformers/dofa-base-patch16-224"
pipe = pipeline(
task="dofa-feature-extraction",
model=MODEL,
trust_remote_code=True,
)
# Native-resolution patch, e.g. 512×512×9 bands (uint8 or float)
features = pipe(image_array, pool=True, return_tensors=True)
Dense features:
tokens = pipe(image_array, pool=False, return_tensors=True)
Opt in to 224×224 resize (original pretraining size):
features = pipe(
image_array,
pool=True,
return_tensors=True,
image_processor_kwargs={"do_resize": True},
)
Override Sentinel-2 defaults for other sensors:
features = pipe(
image_array,
wavelengths=[...],
image_mean=[...],
image_std=[...],
pool=True,
return_tensors=True,
)
conda activate rsgen
python test_dofa.py
python test_dofa.py --model dofa-large-patch16-224
python test_dofa.py --model dofa-base-patch16-224 --no-pool
transformerstimmtorchopencv-python (only when resizing inputs with more than 4 channels)