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.0.tar.gz (25.9 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.0-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: opensr_utils-1.0.0.tar.gz
  • Upload date:
  • Size: 25.9 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.0.tar.gz
Algorithm Hash digest
SHA256 98d2be0fa545beec33629852ce22c5bb94d856b5168e3b943482e840dc908cb9
MD5 c3058db4e07a3961adbedd90c497a99d
BLAKE2b-256 00376b6c11f4d3c8478ffba1eb5ed17dcdff892eb2097e1548856b38e43beef6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: opensr_utils-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 27.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88ba90148a650db0be2035f85674fdb1860b635dda00b2a8715922234c852ee0
MD5 2e1ac26d6ac06cbeb48f363b93e10dbf
BLAKE2b-256 db82dd91ead1db073e5b262554b9dd33b047d7e5a44e9161d5b0b86e35ce8cfe

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