SAMRefiner#

class geowombat.detect.SAMRefiner(checkpoint, model_type='vit_b', device='auto')[source]#

Bases: object

Refine bounding-box detections into polygons using SAM.

Each input box is used as a prompt to the Segment Anything model (or SAM2 if installed) to produce a precise polygon mask, then polygonized back into vector geometry in the source CRS.

Requires: pip install geowombat[sam]

Parameters:
checkpointstr or Path

Path to a SAM checkpoint (sam_vit_b.pth, etc).

model_type{‘vit_b’, ‘vit_l’, ‘vit_h’}

SAM backbone size. Default ‘vit_b’.

devicestr

‘cpu’, ‘cuda’, or ‘auto’. Default ‘auto’.

Methods

refine(src, boxes_gdf[, band_indices, ...])

Refine boxes to polygon masks.

Methods Summary

refine(src, boxes_gdf[, band_indices, ...])

Refine boxes to polygon masks.

Methods Documentation

refine(src, boxes_gdf, band_indices=None, scale=None, pad_pixels=8, simplify_tolerance=0.5)[source]#

Refine boxes to polygon masks.

Parameters:
srcxarray.DataArray

Source raster (must match boxes_gdf.crs).

boxes_gdfgeopandas.GeoDataFrame

Detector output. Each row’s geometry should be the bbox.

band_indiceslist of int, optional

RGB bands for SAM input.

scaletuple of (lo, hi), optional

Stretch range.

pad_pixelsint

Pad around each box when reading the chip. Default 8.

simplify_tolerancefloat

Polygon simplification tolerance in CRS units. Default 0.5.

Returns:
geopandas.GeoDataFrame

Same columns as input; geometry replaced by polygons.

refine(src, boxes_gdf, band_indices=None, scale=None, pad_pixels=8, simplify_tolerance=0.5)[source]#

Refine boxes to polygon masks.

Parameters:
srcxarray.DataArray

Source raster (must match boxes_gdf.crs).

boxes_gdfgeopandas.GeoDataFrame

Detector output. Each row’s geometry should be the bbox.

band_indiceslist of int, optional

RGB bands for SAM input.

scaletuple of (lo, hi), optional

Stretch range.

pad_pixelsint

Pad around each box when reading the chip. Default 8.

simplify_tolerancefloat

Polygon simplification tolerance in CRS units. Default 0.5.

Returns:
geopandas.GeoDataFrame

Same columns as input; geometry replaced by polygons.