opengeos / segment-geospatial

A Python package for segmenting geospatial data with the Segment Anything Model (SAM)
https://samgeo.gishub.org
MIT License
3.04k stars 313 forks source link

Unable to merge large rasters when using text prompt in batch segmentation #181

Open Ankit-Vohra opened 1 year ago

Ankit-Vohra commented 1 year ago

I'm trying to run batch segmentation on a orthomosaic of 4gb, what should be the free storage required in my system if I have to merge all the tiles and build one single raster out of all the masks. Settings which I have used:

  1. Tile size: 1000*1000
  2. Overlap: 100pixels
  3. Total tiles: 1568

My code is executing fine but it throws error that disk is full while merging all the masks although I have over 200 gb storage available in my disk.

giswqs commented 1 year ago

Please provide the source code that you used.

Ankit-Vohra commented 1 year ago

import leafmap
from samgeo import tms_to_geotiff, split_raster
from samgeo.text_sam import LangSAM

image = "ortho.tif"
split_raster(image, out_dir="tiles", tile_size=(1024, 1024), overlap=100)

sam = LangSAM()

text_prompt = "tree"

sam.predict_batch(
    images='tiles',
    out_dir='masks_25',
    text_prompt=text_prompt,
    box_threshold=0.25,
    text_threshold=0.24,
    mask_multiplier=255,
    dtype='uint8',
    merge=True,
    verbose=True,
)
giswqs commented 1 year ago

Try setting merge=False to see what happens.