Skip to main content

Autodistill HLS Geospatial Module

This repository contains the code supporting the HLS Geospatial base model for use with Autodistill.

Harmonized Landsat and Sentinel-2 (HLS) Prithvi is a collection of foundation models for geospatial analysis, developed by NASA and IBM. You can use Autodistill to automatically label images for use in training segmentation models.

The following models are supported:

This module accepts tiff files as input and returns segmentation masks.

Read the full Autodistill documentation.

Read the HLS Geospatial Autodistill documentation.

Installation

To use HLS Geospatial with autodistill, you need to install the following dependency:

pip3 install autodistill-hls-geospatial

Quickstart

from autodistill_hls_geospatial import HLSGeospatial
import numpy as np
import rasterio
from skimage import exposure
import supervision as sv

from autodistill_hls_geospatial import HLSGeospatial

def stretch_rgb(rgb):
    ls_pct = 1
    pLow, pHigh = np.percentile(rgb[~np.isnan(rgb)], (ls_pct, 100 - ls_pct))
    img_rescale = exposure.rescale_intensity(rgb, in_range=(pLow, pHigh))

    return img_rescale


#replace with the name of the file you want to label
FILE_NAME = "USA_430764_S2Hand.tif"

with rasterio.open(FILE_NAME) as src:
    image = src.read()

    mask = image

    rgb = stretch_rgb(
        (mask[[3, 2, 1], :, :].transpose((1, 2, 0)) / 10000 * 255).astype(np.uint8)
    )

    base_model = HLSGeospatial()

    # replace with the file you want to use
    detections = base_model.predict(FILE_NAME)

    mask_annotator = sv.MaskAnnotator()

    annotated_image = mask_annotator.annotate(scene=rgb, detections=detections)

    sv.plot_image(annotated_image, size=(10, 10))

# label a folder of .tif files
base_model.label("./context_images", extension=".tif")

License

This project is licensed under an Apache 2.0 license.

🏆 Contributing

We love your input! Please see the core Autodistill contributing guide to get started. Thank you 🙏 to all our contributors!

Release files for autodistill-hls-geospatial 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autodistill-hls-geospatial 0.1.0
File Size Uploaded
autodistill-hls-geospatial-0.1.0.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autodistill-hls-geospatial 0.1.0
File Interpreter ABI Platform
autodistill_hls_geospatial-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / autodistill-hls-geospatial-0.1.0.tar.gz

Download URL autodistill-hls-geospatial-0.1.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5635cb091156bd3f1787aabb091be113006fb6c37ce567f90522d3b886da1e58
BLAKE2b-256 checksum
How to use checksums
cfa692c059faa714bd45c3534a54a653b6157330b2ec1d31d2bb950ddccc410b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / autodistill_hls_geospatial-0.1.0-py3-none-any.whl

Download URL autodistill_hls_geospatial-0.1.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29aae0b63f6dbb5e48b155674f329c368caa31f7e9937824f31d90a670bcdd33
BLAKE2b-256 checksum
How to use checksums
2b98bb62feb491f157f41d47dee3935bee4122d36e49dbaf21d6186d9dd79db3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page