File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change 22
33To use segment-geospatial in a project:
44
5- ```
5+ ``` python
66import samgeo
77```
8+
9+ Here is a simple example of using segment-geospatial to generate a segmentation mask from a satellite image:
10+
11+ ``` python
12+ import os
13+ import torch
14+ from samgeo import SamGeo, tms_to_geotiff
15+
16+ bbox = [- 95.3704 , 29.6762 , - 95.368 , 29.6775 ]
17+ image = ' satellite.tif'
18+ tms_to_geotiff(output = image, bbox = bbox, zoom = 20 , source = ' Satellite' )
19+
20+ out_dir = os.path.join(os.path.expanduser(' ~' ), ' Downloads' )
21+ checkpoint = os.path.join(out_dir, ' sam_vit_h_4b8939.pth' )
22+
23+ device = ' cuda' if torch.cuda.is_available() else ' cpu'
24+ sam = SamGeo(
25+ checkpoint = checkpoint,
26+ model_type = ' vit_h' ,
27+ device = device,
28+ erosion_kernel = (3 , 3 ),
29+ mask_multiplier = 255 ,
30+ sam_kwargs = None ,
31+ )
32+
33+ mask = ' segment.tiff'
34+ sam.generate(image, mask)
35+
36+ vector = ' segment.gpkg'
37+ sam.tiff_to_gpkg(mask, vector, simplify_tolerance = None )
38+ ```
39+
40+ ![ ] ( https://i.imgur.com/Ysq3u7E.png )
You can’t perform that action at this time.
0 commit comments