Skip to content

Commit f409834

Browse files
authored
Added non-interactive example (#11)
1 parent 6dbd13e commit f409834

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

docs/usage.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22

33
To use segment-geospatial in a project:
44

5-
```
5+
```python
66
import 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)

0 commit comments

Comments
 (0)