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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file autodistill-hls-geospatial-0.1.0.tar.gz
.
File metadata
- Download URL: autodistill-hls-geospatial-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5635cb091156bd3f1787aabb091be113006fb6c37ce567f90522d3b886da1e58 |
|
MD5 | 88d81713dd2179766ce776f622edff87 |
|
BLAKE2b-256 | cfa692c059faa714bd45c3534a54a653b6157330b2ec1d31d2bb950ddccc410b |
File details
Details for the file autodistill_hls_geospatial-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: autodistill_hls_geospatial-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29aae0b63f6dbb5e48b155674f329c368caa31f7e9937824f31d90a670bcdd33 |
|
MD5 | e25c94b2e5fae04561e1db538d8b747f |
|
BLAKE2b-256 | 2b98bb62feb491f157f41d47dee3935bee4122d36e49dbaf21d6186d9dd79db3 |