Skip to main content

Utilities supporting the ESA opensr-model package for Super-Resolution of Senintel-2 Imagery

Project description

opensr-utils - Efficient Multi-GPU Super-Resolution of Large Scale S2-EO Data

🚀 Fast multi-GPU super-resolution for massive Sentinel-2 imagery 🌍 — seamless weighted blending ✨ removes patch artifacts, while flexible input support (.SAFE 📂, S2GM 🛰️, GeoTIFF 🗺️) makes generating high-quality SR products effortless.

WARNING

  • This Repo is currently udnergoing major revision
  • It is functional for RGB+NIR images currently.
  • Functionalities coming in the future:
    • Pass more file types
    • Run SR for a selectable amount of bands

img1

Description

This package performs super-resolution with any PyTorch or PyTorch lighning model for the Sentinel-2 10m bands (R-G-B-NIR).

Functionalities:

  • The Input can be either:
    • a ".SAFE" folder, zipped or unzipped.
    • a "S2GM" folder as available from the S2 Global Mosaic Hub
    • any ".tif" file or similar that can be laoded by rasterio
  • The following is performed automatically:
    • Patching of input images by selectable size (eg 128x128)
    • Super-Resolution of individual patches with provided model
    • writing of georeferenced output raster
    • overlapping and sigmoid weightning of patches by selectable pixel amount to reduce patching artifacts - See image
    • CPU, GPU and multi-GPU inference is supported via PL-Lightning
  • Supported Models:
    • 'LightningModule': Any PL Lightning model with a .predict() or .forward() function. If this model type is passed, multi-GPU and multi-batch processing is activated, which leads to a significant inference speed increase.
    • 'torch.nn.Module': Any SR model with a .forward() function can be passed. The drawback is that for this model type, multi-GPU and multi-batch processing is not supported. This is therefore considerably slower.

Usage example:

First, download a .SAFE tile from the Copernicus Browser, a Mosaic folder from S2G, or get your RGB-NIR .tif file ready.

1. install libraries

pip install opensr-utils
pip install opensr-model

2. Create Model - in this case our LDSR-S2 Model

# Instanciate Model
import opensr_model # import pachage
model = opensr_model.SRLatentDiffusion(config, device=device) # create model
model.load_pretrained(config.ckpt_version) # load checkpoint

3. Run large-scale Inference

#
import opensr_utils
sr_object = opensr_utils.large_file_processing( 
				root=path, # File or Folder path
				model=None, # your SR model
				window_size=(128, 128), # LR window size for patching
				factor=4, # SR factor
				overlap=12, # amount of overlapping pixels that are weighted to avoid artifacts
				eliminate_border_px=2, # amount of pixels taht are discarded along the edges
				device="cuda", # set 'cuda' for GPU-accelerated inference
				gpus=0, # pass GPU ID or list of GPUs
				)
sr_object.start_super_resolution()

Overlapping Strategy

In order to avoid patching artifacts that are present in many SR products, we perform a weighting based on the distance to the edge of the patches. It can be a linear weighting, but what works best is a sigmoid weight curve which puts leads to a more even edge. Additionally, in order to eliminate edge-artifacts that are present in many SR models, it is also possible to discard a fixed number of pixels along the edges of all patches. img3 img4

Example of Patching Artifacts in other SR models:
img5

Downloads

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opensr_utils-1.0.1.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opensr_utils-1.0.1-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file opensr_utils-1.0.1.tar.gz.

File metadata

  • Download URL: opensr_utils-1.0.1.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for opensr_utils-1.0.1.tar.gz
Algorithm Hash digest
SHA256 16774300bab002baf79d400e6b450bbc2698935ee13fd08a3fe1d1ea1d14a265
MD5 68e9dda4f54bfa39f98187da6c8d043f
BLAKE2b-256 0d41a90af80780eddffa27655adf7efa057a7d188e5639882605d0bd2f81d570

See more details on using hashes here.

File details

Details for the file opensr_utils-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: opensr_utils-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for opensr_utils-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a85c9dc5b717271bd0fcf7986c91839242d011350a0f6dcdb1db9197c3cb194a
MD5 c1a34806fab71bd2b9ac628b7ff0480b
BLAKE2b-256 6f7ddf29b573c496e13d786a0cea9637dbf076ca821f738488eecd65daa0d03d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page