Skip to content

Commit dab8b84

Browse files
authored
Update IPPN workshop notebook (#331)
1 parent b494a2b commit dab8b84

File tree

1 file changed

+110
-4
lines changed

1 file changed

+110
-4
lines changed

docs/workshops/IPPN_2024.ipynb

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"source": [
1010
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/segment-geospatial/blob/main/docs/workshops/IPPN_2024.ipynb)\n",
1111
"\n",
12-
"**Open Source Pipeline for UAS and satellite based High Throughput Phenotyping Applications**\n",
12+
"**Open Source Pipeline for UAS and satellite based High Throughput Phenotyping Applications - Part 1**\n",
1313
"\n",
14-
"This notebook is designed for workshop presented at the [International Plant Phenotyping Network (IPPN)](https://www.plant-phenotyping.org/ipps8) conference on October 7, 2024. Click the **Open in Colab** button above to run this notebook interactively in the cloud.\n",
14+
"This notebook is designed for workshop presented at the [International Plant Phenotyping Network (IPPN)](https://www.plant-phenotyping.org/ipps8) conference on October 7, 2024. Click the **Open in Colab** button above to run this notebook interactively in the cloud. For Part 2 of the workshop, please click [here](https://geemap.org/workshops/IPPN_2024/).\n",
1515
"\n",
1616
"- Registration: <https://www.plant-phenotyping.org/index.php?index=935>\n",
1717
"- Notebook: <https://samgeo.gishub.org/workshops/IPPN_2024>\n",
@@ -946,7 +946,7 @@
946946
"metadata": {},
947947
"outputs": [],
948948
"source": [
949-
"from samgeo import SamGeo2"
949+
"from samgeo import SamGeo, SamGeo2"
950950
]
951951
},
952952
{
@@ -1212,14 +1212,120 @@
12121212
" label2=\"Image Segmentation\",\n",
12131213
")"
12141214
]
1215+
},
1216+
{
1217+
"cell_type": "markdown",
1218+
"id": "105",
1219+
"metadata": {},
1220+
"source": [
1221+
"### Using box prompts"
1222+
]
1223+
},
1224+
{
1225+
"cell_type": "code",
1226+
"execution_count": null,
1227+
"id": "106",
1228+
"metadata": {},
1229+
"outputs": [],
1230+
"source": [
1231+
"gdf = leafmap.geojson_to_gdf(tree_boundaries)\n",
1232+
"gdf.head()"
1233+
]
1234+
},
1235+
{
1236+
"cell_type": "code",
1237+
"execution_count": null,
1238+
"id": "107",
1239+
"metadata": {},
1240+
"outputs": [],
1241+
"source": [
1242+
"geojson = \"tree_boundaries.geojson\"\n",
1243+
"gdf.to_file(geojson)"
1244+
]
1245+
},
1246+
{
1247+
"cell_type": "code",
1248+
"execution_count": null,
1249+
"id": "108",
1250+
"metadata": {},
1251+
"outputs": [],
1252+
"source": [
1253+
"m = leafmap.Map()\n",
1254+
"m.add_raster(image, layer_name=\"image\")\n",
1255+
"style = {\n",
1256+
" \"color\": \"#ffff00\",\n",
1257+
" \"weight\": 2,\n",
1258+
" \"fillColor\": \"#7c4185\",\n",
1259+
" \"fillOpacity\": 0,\n",
1260+
"}\n",
1261+
"m.add_vector(geojson, style=style, zoom_to_layer=True, layer_name=\"Bounding boxes\")\n",
1262+
"m"
1263+
]
1264+
},
1265+
{
1266+
"cell_type": "code",
1267+
"execution_count": null,
1268+
"id": "109",
1269+
"metadata": {},
1270+
"outputs": [],
1271+
"source": [
1272+
"sam = SamGeo(\n",
1273+
" model_type=\"vit_h\",\n",
1274+
" automatic=False,\n",
1275+
" sam_kwargs=None,\n",
1276+
")"
1277+
]
1278+
},
1279+
{
1280+
"cell_type": "code",
1281+
"execution_count": null,
1282+
"id": "110",
1283+
"metadata": {},
1284+
"outputs": [],
1285+
"source": [
1286+
"sam.set_image(image)"
1287+
]
1288+
},
1289+
{
1290+
"cell_type": "code",
1291+
"execution_count": null,
1292+
"id": "111",
1293+
"metadata": {},
1294+
"outputs": [],
1295+
"source": [
1296+
"sam.predict(\n",
1297+
" boxes=geojson, point_crs=\"EPSG:4326\", output=\"tree_masks.tif\", dtype=\"uint16\"\n",
1298+
")"
1299+
]
1300+
},
1301+
{
1302+
"cell_type": "code",
1303+
"execution_count": null,
1304+
"id": "112",
1305+
"metadata": {},
1306+
"outputs": [],
1307+
"source": [
1308+
"m.add_raster(\n",
1309+
" \"tree_masks.tif\", cmap=\"jet\", nodata=0, opacity=0.5, layer_name=\"Tree masks\"\n",
1310+
")\n",
1311+
"m"
1312+
]
1313+
},
1314+
{
1315+
"cell_type": "markdown",
1316+
"id": "113",
1317+
"metadata": {},
1318+
"source": [
1319+
"![image](https://github.com/user-attachments/assets/0a9b794d-cf94-4e5c-9134-8799e67d338c)"
1320+
]
12151321
}
12161322
],
12171323
"metadata": {
12181324
"colab": {
12191325
"provenance": []
12201326
},
12211327
"kernelspec": {
1222-
"display_name": "Python 3 (ipykernel)",
1328+
"display_name": "sam",
12231329
"language": "python",
12241330
"name": "python3"
12251331
},

0 commit comments

Comments
 (0)