Skip to main content

Python library for cloud and cloud shadow segmentation in Sentinel-2

Project description

Welcome to CloudS2Mask ☁️

GitHub Version Last Commit

💡 About

CloudS2Mask is an open-source Python library that efficiently segments clouds and cloud shadows in Sentinel-2 imagery using state-of-the-art deep learning techniques. Benchmarks with the CloudSEN12 Dataset show a 17% error reduction compared to the most competent existing methods.

🎯 Features

  • High-precision cloud and cloud shadow segmentation for Sentinel-2 L1C imagery.
  • Rapid processing: Approximately 2.2 seconds per scene at 20m resolution (RTX 4090, AMD Ryzen 9 5950X).
  • Compatibility with both GPU and non-GPU systems.
  • Supported on Linux, Windows, and macOS.

🚀 Installation

Windows Users with NVIDIA GPUs: Before installing CloudS2Mask, ensure you've installed PyTorch with CUDA support, then follow the steps below.

Mac and Linux Users: You can proceed with the installation commands below. To install CloudS2Mask, clone this repository and proceed with manual installation.

git clone https://github.com/DPIRD-DMA/CloudS2Mask
cd CloudS2Mask
pip install -q .
cd ..

💻 Usage

Here's a simple demonstration of how to use CloudS2Mask:

All you need to do is pass a list of Sentinel-2 level 1C 'SAFE' directories to CloudS2Mask.

Colab_Button

from pathlib import Path
from clouds2mask import (
    create_settings,
    batch_process_scenes,
)

output_dir = Path("./outputs")
l1c_folders_path = Path("/path/to/your/S2_l1c_SAFE/folders")
l1c_folders = list(l1c_folders_path.glob("*.SAFE"))


scene_settings = create_settings(
    sent_safe_dirs=l1c_folders,
    output_dir=output_dir,
    processing_res=20,
)

paths_to_masks = batch_process_scenes(scene_settings)

⚙️ Performance Tuning

CloudsS2Mask offers a range of performance and accuracy options, here are some examples,

Settings for high accuracy inference:

scene_settings = create_settings(
    sent_safe_dirs=l1c_folders,
    output_dir=output_dir,
    batch_size=32,
    tta_max_depth=5,
    processing_res=10,
    patch_overlap_px=64,
    model_ensembling=True,
)

Settings for fast inference:

scene_settings = create_settings(
    sent_safe_dirs=l1c_folders,
    output_dir=output_dir,
    batch_size=32,
    processing_res=20,
    output_compression=None,
)

Settings for CPU inference:

scene_settings = create_settings(
    sent_safe_dirs=l1c_folders,
    output_dir=output_dir,
    batch_size=1,
    processing_res=20,
)

CloudS2Mask will try to auto detect acceleration cards such as NVIDIA GPUs or Apple MPS, but you can also manually specify them like this:

scene_settings = create_settings(
    sent_safe_dirs=l1c_folders,
    output_dir=output_dir,
    pytorch_device='MPS',
)

👏 Contributing

We welcome all contributions! Feel free to open an issue or submit a pull request.

📄 License

This project is licensed under the MIT License - please refer to the LICENSE file for more details.

📝 Contact

For support, bug reporting, or to contribute, feel free to reach out at nicholas.wright@dpird.wa.gov.au.

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

clouds2mask-0.1.6.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

clouds2mask-0.1.6-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file clouds2mask-0.1.6.tar.gz.

File metadata

  • Download URL: clouds2mask-0.1.6.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for clouds2mask-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ad9d43ab5a184f22b3bd13fd6dbafbc16923912f53d66e51df5c67e635eb9e82
MD5 991b12924c03aa1919367640c1fd1b52
BLAKE2b-256 8152a00bc730ff3a994e2c863dd784565e3d1dd298664b023bf775c82e5187eb

See more details on using hashes here.

File details

Details for the file clouds2mask-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: clouds2mask-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for clouds2mask-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e34a83a2399aa1e716ce0f014783242815a26c0275066062429bd4aef2f42ccb
MD5 02c4662da85a9444f2e10f732bf5a985
BLAKE2b-256 1b93ab7207dab83746c89e47edf50dc1d195b557c4731330d5d7dacbffd45c43

See more details on using hashes here.

Supported by

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