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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc0-1.0
|
| 3 |
+
base_model: tacofoundation/SEN2SR
|
| 4 |
+
tags:
|
| 5 |
+
- sentinel-2
|
| 6 |
+
- super-resolution
|
| 7 |
+
- remote-sensing
|
| 8 |
+
- pytorch
|
| 9 |
+
pipeline_tag: image-to-image
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
<p align="center">
|
| 13 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/6402474cfa1acad600659e92/G1o2oiRwJaqw4ZP9nG0NO.webp" width="100%">
|
| 14 |
+
</p>
|
| 15 |
+
|
| 16 |
+
<p align="center">
|
| 17 |
+
<em>Sentinel-2 super-resolution up to 2.5 m — WEO-SAS packaging of <a href="https://huggingface.co/tacofoundation/SEN2SR">tacofoundation/SEN2SR</a></em>
|
| 18 |
+
</p>
|
| 19 |
+
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
This repository re-packages the original [tacofoundation/SEN2SR](https://huggingface.co/tacofoundation/SEN2SR) models with the **WEO-SAS standard interface** (`model.py`, `predictor.py`, `config.json`) so they can be loaded and used identically to all other WEO-SAS models.
|
| 23 |
+
|
| 24 |
+
**Original work:** [ESAOpenSR/sen2sr](https://github.com/ESAOpenSR/sen2sr) — license CC0-1.0.
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## Model Variants
|
| 29 |
+
|
| 30 |
+
Six variants are available as **HuggingFace branches**, each with a different architecture, input bands, and upscaling factor.
|
| 31 |
+
|
| 32 |
+
| Branch | Architecture | Input bands | Output bands | Scale | Description |
|
| 33 |
+
|---|---|---|---|---|---|
|
| 34 |
+
| `main` *(default)* | CNN | 4 (RGBN) | 4 (RGBN) | 4× | SEN2SRLite — RGBN 10 m → 2.5 m |
|
| 35 |
+
| `lite-rswir-x2` | CNN | 10 (all S2) | 6 (RSWIR) | 2× | SEN2SRLite — 20 m bands → 10 m |
|
| 36 |
+
| `lite-main` | CNN | 10 (all S2) | 10 (all S2) | 4× | SEN2SRLite — full 10-band pipeline 10 m → 2.5 m |
|
| 37 |
+
| `mamba-rgbn-x4` | Mamba | 4 (RGBN) | 4 (RGBN) | 4× | SEN2SR — RGBN 10 m → 2.5 m (higher accuracy) |
|
| 38 |
+
| `mamba-rswir-x2` | Swin2SR | 10 (all S2) | 6 (RSWIR) | 2× | SEN2SR — 20 m bands → 10 m (higher accuracy) |
|
| 39 |
+
| `mamba-main` | Mamba + Swin2SR | 10 (all S2) | 10 (all S2) | 4× | SEN2SR — full 10-band pipeline (highest accuracy) |
|
| 40 |
+
|
| 41 |
+
**Band order expected as input:**
|
| 42 |
+
|
| 43 |
+
| Variant | Bands |
|
| 44 |
+
|---|---|
|
| 45 |
+
| RGBN (`main`, `mamba-rgbn-x4`) | B04, B03, B02, B08 |
|
| 46 |
+
| All others (10 bands) | B04, B03, B02, B08, B05, B06, B07, B8A, B11, B12 |
|
| 47 |
+
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
## Installation
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
# For CNN variants (main, lite-rswir-x2, lite-main)
|
| 54 |
+
pip install sen2sr safetensors huggingface_hub rasterio
|
| 55 |
+
|
| 56 |
+
# For Mamba/Swin variants (mamba-*)
|
| 57 |
+
pip install mamba-ssm --no-build-isolation
|
| 58 |
+
pip install sen2sr safetensors huggingface_hub rasterio
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
---
|
| 62 |
+
|
| 63 |
+
## Usage
|
| 64 |
+
|
| 65 |
+
All variants share the **same interface**. Only the `revision` argument changes.
|
| 66 |
+
|
| 67 |
+
### Load any variant
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from huggingface_hub import snapshot_download
|
| 71 |
+
import sys
|
| 72 |
+
|
| 73 |
+
# Choose your variant:
|
| 74 |
+
local_dir = snapshot_download("WEO-SAS/sen2sr") # RGBN 4x (CNN) — default
|
| 75 |
+
local_dir = snapshot_download("WEO-SAS/sen2sr", revision="lite-rswir-x2") # RSWIR 2x (CNN)
|
| 76 |
+
local_dir = snapshot_download("WEO-SAS/sen2sr", revision="lite-main") # Full 10-band 4x (CNN)
|
| 77 |
+
local_dir = snapshot_download("WEO-SAS/sen2sr", revision="mamba-rgbn-x4") # RGBN 4x (Mamba)
|
| 78 |
+
local_dir = snapshot_download("WEO-SAS/sen2sr", revision="mamba-rswir-x2")# RSWIR 2x (Swin2SR)
|
| 79 |
+
local_dir = snapshot_download("WEO-SAS/sen2sr", revision="mamba-main") # Full 10-band 4x (Mamba+Swin)
|
| 80 |
+
|
| 81 |
+
sys.path.insert(0, local_dir)
|
| 82 |
+
from model import Model
|
| 83 |
+
|
| 84 |
+
model = Model(local_dir=local_dir)
|
| 85 |
+
print(model.description)
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
### Array inference
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
import numpy as np
|
| 92 |
+
|
| 93 |
+
# image: (C, H, W) float32, values in [0, 1] (C=4 for RGBN, C=10 for full-band)
|
| 94 |
+
image = np.random.rand(4, 128, 128).astype("float32")
|
| 95 |
+
|
| 96 |
+
sr = model.predict(image) # (C, H*4, W*4) float32
|
| 97 |
+
print(sr.shape) # (4, 512, 512)
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
### GeoTIFF pipeline
|
| 101 |
+
|
| 102 |
+
Reads Sentinel-2 DN values directly (auto-normalises by /10000), writes a super-resolved GeoTIFF with the correct pixel size.
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
model.predict_tif(
|
| 106 |
+
input_path = "s2_scene_10m.tif",
|
| 107 |
+
output_path = "s2_scene_2p5m.tif",
|
| 108 |
+
bands = [0, 1, 2, 3], # 0-based band indices (default: first C bands)
|
| 109 |
+
)
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
### Override config at load time
|
| 113 |
+
|
| 114 |
+
```python
|
| 115 |
+
model = Model(local_dir=local_dir, patch_size=256, overlap=64)
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## RGBN 10 m → 2.5 m (`main`, `mamba-rgbn-x4`)
|
| 121 |
+
|
| 122 |
+
Super-resolves the four 10 m Sentinel-2 bands (Red, Green, Blue, NIR) by 4×.
|
| 123 |
+
|
| 124 |
+
<p align="center">
|
| 125 |
+
<img src="https://huggingface.co/tacofoundation/SEN2SR/resolve/main/assets/srimg02.png" width="100%">
|
| 126 |
+
</p>
|
| 127 |
+
|
| 128 |
+
---
|
| 129 |
+
|
| 130 |
+
## Full 10-band 10 m → 2.5 m (`lite-main`, `mamba-main`)
|
| 131 |
+
|
| 132 |
+
Multi-stage pipeline: RGBN bands are super-resolved at 4×, while the 20 m bands (B05, B06, B07, B8A, B11, B12) are first sharpened to 10 m then to 2.5 m. All 10 bands are returned at 2.5 m.
|
| 133 |
+
|
| 134 |
+
<p align="center">
|
| 135 |
+
<img src="https://huggingface.co/tacofoundation/SEN2SR/resolve/main/assets/srimg01.png" width="100%">
|
| 136 |
+
</p>
|
| 137 |
+
|
| 138 |
+
---
|
| 139 |
+
|
| 140 |
+
## RSWIR 20 m → 10 m (`lite-rswir-x2`, `mamba-rswir-x2`)
|
| 141 |
+
|
| 142 |
+
Sharpens the six 20 m Sentinel-2 bands (B05, B06, B07, B8A, B11, B12) to 10 m resolution using all 10 bands as context input.
|
| 143 |
+
|
| 144 |
+
<p align="center">
|
| 145 |
+
<img src="https://huggingface.co/tacofoundation/SEN2SR/resolve/main/assets/srimg03.png" width="100%">
|
| 146 |
+
</p>
|
| 147 |
+
|
| 148 |
+
---
|
| 149 |
+
|
| 150 |
+
## Large image inference
|
| 151 |
+
|
| 152 |
+
For images larger than the 128×128 training patch size, `predict_tif` and `predict` automatically tile the input with overlapping patches and blend them seamlessly.
|
| 153 |
+
|
| 154 |
+
<p align="center">
|
| 155 |
+
<img src="https://huggingface.co/tacofoundation/SEN2SR/resolve/main/assets/srimg05.png" width="95%">
|
| 156 |
+
</p>
|
| 157 |
+
|
| 158 |
+
---
|
| 159 |
+
|
| 160 |
+
## Repository structure
|
| 161 |
+
|
| 162 |
+
Each branch contains a flat directory with the same set of files:
|
| 163 |
+
|
| 164 |
+
```
|
| 165 |
+
config.json # Variant-specific inference parameters
|
| 166 |
+
model.py # Public entry point (WEO-SAS standard)
|
| 167 |
+
predictor.py # Tiled inference logic
|
| 168 |
+
sen2sr_pt.py # HF-aware model loader (handles CNN / Mamba / Swin)
|
| 169 |
+
base.py # Abstract base class
|
| 170 |
+
model.safetensor # Primary model weights
|
| 171 |
+
hard_constraint.safetensor# Hard-constraint weights
|
| 172 |
+
load.py # Original tacofoundation loading script
|
| 173 |
+
mlm.json # Original MLSTAC metadata
|
| 174 |
+
# multi-stage branches also include:
|
| 175 |
+
sr_model.safetensor / sr_hard_constraint.safetensor (RGBN stage)
|
| 176 |
+
f2_model.safetensor / f2_hard_constraint.safetensor (RSWIR 2x stage)
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
---
|
| 180 |
+
|
| 181 |
+
## Citation
|
| 182 |
+
|
| 183 |
+
If you use these models please cite the original work:
|
| 184 |
+
|
| 185 |
+
```bibtex
|
| 186 |
+
@software{sen2sr2024,
|
| 187 |
+
author = {Aybar, Cesar and others},
|
| 188 |
+
title = {SEN2SR: Sentinel-2 Super-Resolution},
|
| 189 |
+
url = {https://github.com/ESAOpenSR/sen2sr},
|
| 190 |
+
year = {2024}
|
| 191 |
+
}
|
| 192 |
+
```
|