Skip to main content

Use the HLS Geospatial model made by NASA and IBM to generate masks for use in training a fine-tuned segmentation model.

Project description

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!

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

autodistill-hls-geospatial-0.1.0.tar.gz (9.5 kB view hashes)

Uploaded Source

Built Distribution

autodistill_hls_geospatial-0.1.0-py3-none-any.whl (10.3 kB view hashes)

Uploaded Python 3

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