{"slug": "a-tutorial-on-geoai-designing-footprint-extraction-from-naip-imagery-using-u-net", "title": "A Tutorial on GeoAI: Designing Footprint Extraction from NAIP Imagery Using U-Net, Grounding DINO, SAM, and Mask R-CNN", "summary": "A new tutorial from the open-source GeoAI project demonstrates a complete workflow for extracting building footprints from NAIP aerial imagery using U-Net with a ResNet-34 encoder, Grounding DINO, SAM, and Mask R-CNN. The tutorial, published on GitHub, covers environment setup, data preparation, model training, inference, and evaluation, including zero-shot segmentation and comparison with a pretrained Mask R-CNN model. It also shows how to extend the pipeline to real-world areas using NAIP imagery from Microsoft Planetary Computer and building labels from Overture Maps.", "body_md": "In this tutorial, we design a complete[ GeoAI](https://github.com/opengeos/geoai) workflow for extracting building footprints from high-resolution NAIP aerial imagery. We begin by configuring the geospatial deep learning environment, downloading raster imagery and vector labels, and inspecting their spatial properties before generating georeferenced image chips and segmentation masks. We then train a U-Net model with a ResNet-34 encoder, evaluate its learning behavior, and apply sliding-window inference to an unseen scene. Beyond semantic segmentation, we convert predicted masks into cleaned and regularized building polygons, calculate IoU and F1 metrics, explore zero-shot segmentation with Grounding DINO and SAM, and compare the results with a pretrained Mask R-CNN instance segmentation model. We also demonstrate how the same pipeline extends to real-world areas using NAIP imagery from Microsoft Planetary Computer and building labels from Overture Maps.\n\n``` python\nimport os\nimport subprocess\nimport sys\nimport time\nimport warnings\nwarnings.filterwarnings(\"ignore\")\nIN_COLAB = \"google.colab\" in sys.modules\ndef pip_install(packages, quiet=True):\n   \"\"\"Install packages with pip from inside the notebook process.\"\"\"\n   cmd = [sys.executable, \"-m\", \"pip\", \"install\", \"--upgrade\"]\n   if quiet:\n       cmd.append(\"-q\")\n   subprocess.run(cmd + list(packages), check=False)\ntry:\n   import geoai\nexcept ImportError:\n   print(\">>> Installing geoai-py and friends (takes ~2-4 minutes on Colab)...\")\n   pip_install(\n       [\n           \"geoai-py\",\n           \"segmentation-models-pytorch\",\n           \"buildingregulariser\",\n       ]\n   )\n   try:\n       import geoai\n   except Exception as e:\n       raise SystemExit(\n           f\"Import failed after install ({e}).\\n\"\n           \"=> Runtime > Restart session, then re-run this cell. \"\n           \"The install is cached, so it will be fast the second time.\"\n       )\nimport geopandas as gpd\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport rasterio\nimport torch\nfrom rasterio.plot import plotting_extent\nfrom IPython.display import display\nprint(f\"geoai        : {geoai.__version__}\")\nprint(f\"torch        : {torch.__version__}\")\nprint(f\"CUDA available: {torch.cuda.is_available()}\")\nif torch.cuda.is_available():\n   print(f\"GPU          : {torch.cuda.get_device_name(0)}\")\nelse:\n   print(\"!! No GPU detected. Training will still run but be much slower.\")\n   print(\"   Colab: Runtime > Change runtime type > Hardware accelerator > T4 GPU\")\nDEVICE = geoai.get_device()\nprint(f\"geoai device : {DEVICE}\")\nCFG = {\n   \"tile_size\": 512,\n   \"stride\": 256,\n   \"buffer_radius\": 0,\n   \"architecture\": \"unet\",\n   \"encoder\": \"resnet34\",\n   \"encoder_weights\": \"imagenet\",\n   \"num_channels\": 3,\n   \"num_classes\": 2,\n   \"batch_size\": 8,\n   \"num_epochs\": 12,\n   \"learning_rate\": 1e-3,\n   \"val_split\": 0.2,\n   \"window_size\": 512,\n   \"overlap\": 256,\n   \"run_zero_shot\": True,\n   \"run_pretrained\": True,\n   \"run_real_aoi\": False,\n}\nWORK = \"/content/geoai_tutorial\" if IN_COLAB else os.path.abspath(\"geoai_tutorial\")\nos.makedirs(WORK, exist_ok=True)\nos.chdir(WORK)\nprint(f\"working dir  : {WORK}\")\ndef banner(text):\n   print(\"\\n\" + \"=\" * 92 + f\"\\n  {text}\\n\" + \"=\" * 92)\ndef timed(fn, label):\n   \"\"\"Run fn(), report wall time, never let one step kill the notebook.\"\"\"\n   banner(label)\n   t0 = time.time()\n   try:\n       out = fn()\n       print(f\"\\n[OK] {label}  —  {time.time() - t0:.1f}s\")\n       return out\n   except Exception as exc:\n       import traceback\n       print(f\"\\n[SKIPPED] {label}\\n{type(exc).__name__}: {exc}\")\n       traceback.print_exc(limit=3)\n       return None\nHF = \"https://huggingface.co/datasets/giswqs/geospatial/resolve/main\"\ntrain_raster_url = f\"{HF}/naip_rgb_train.tif\"\ntrain_vector_url = f\"{HF}/naip_train_buildings.geojson\"\ntest_raster_url = f\"{HF}/naip_test.tif\"\ndef step1():\n   train_raster = geoai.download_file(train_raster_url)\n   train_vector = geoai.download_file(train_vector_url)\n   test_raster = geoai.download_file(test_raster_url)\n   for p in (train_raster, train_vector, test_raster):\n       print(f\"  {os.path.getsize(p) / 1e6:8.2f} MB  {p}\")\n   return train_raster, train_vector, test_raster\npaths = timed(step1, \"STEP 1 — Downloading sample NAIP imagery and building labels\")\nTRAIN_RASTER, TRAIN_VECTOR, TEST_RASTER = paths\n```\n\nWe configure the environment, install the required GeoAI and deep learning libraries, and verify GPU availability. We define the central configuration parameters for dataset creation, model training, inference, and optional processing stages. We then create the working directory, define reusable execution utilities, and download the NAIP imagery and building footprint labels.\n\n``` python\ndef step2():\n   info = geoai.get_raster_info(TRAIN_RASTER)\n   for k, v in info.items():\n       print(f\"  {k:<16}: {v}\")\n   print(\"\\n--- per-band statistics ---\")\n   print(geoai.get_raster_stats(TRAIN_RASTER))\n   print(\"\\n--- vector info ---\")\n   vinfo = geoai.get_vector_info(TRAIN_VECTOR)\n   for k, v in vinfo.items():\n       print(f\"  {k:<16}: {v}\")\n   gdf = gpd.read_file(TRAIN_VECTOR)\n   print(f\"\\n  {len(gdf)} training buildings | CRS {gdf.crs}\")\n   print(gdf.head(3))\n   geoai.view_vector(\n       gdf,\n       raster_path=TRAIN_RASTER,\n       outline_only=True,\n       edge_color=\"yellow\",\n       outline_linewidth=0.8,\n       figsize=(11, 11),\n       title=\"NAIP training scene + building footprints\",\n   )\n   try:\n       display(geoai.view_vector_interactive(TRAIN_VECTOR, layer_name=\"Buildings\"))\n   except Exception as e:\n       print(f\"  (interactive map unavailable here: {e})\")\n   return gdf\nLABELS_GDF = timed(step2, \"STEP 2 — Inspecting raster + vector data\")\nTILES_DIR = os.path.join(WORK, \"tiles\")\ndef step3():\n   stats = geoai.export_geotiff_tiles(\n       in_raster=TRAIN_RASTER,\n       out_folder=TILES_DIR,\n       in_class_data=TRAIN_VECTOR,\n       tile_size=CFG[\"tile_size\"],\n       stride=CFG[\"stride\"],\n       buffer_radius=CFG[\"buffer_radius\"],\n       all_touched=True,\n       skip_empty_tiles=False,\n       quiet=False,\n   )\n   n_img = len(os.listdir(f\"{TILES_DIR}/images\"))\n   n_lbl = len(os.listdir(f\"{TILES_DIR}/labels\"))\n   print(f\"\\n  chips: {n_img} images / {n_lbl} masks\")\n   if isinstance(stats, dict):\n       tot = max(stats.get(\"total_tiles\", n_img), 1)\n       print(f\"  tiles containing buildings: {stats.get('tiles_with_features')} \"\n             f\"({100 * stats.get('tiles_with_features', 0) / tot:.1f}%)\")\n       print(f\"  foreground pixels: {stats.get('feature_pixels'):,}\")\n   geoai.display_training_tiles(TILES_DIR, num_tiles=6, figsize=(18, 6))\n   return stats\nTILE_STATS = timed(step3, \"STEP 3 — Exporting image chips and label masks\")\n```\n\nWe inspect the raster and vector datasets to understand their coordinate systems, dimensions, statistics, and feature structures. We visualize the building labels over the aerial imagery and generate an interactive map for spatial exploration. We then divide the source imagery into overlapping georeferenced chips and create matching raster masks for model training.\n\n```\nMODEL_DIR = os.path.join(WORK, \"models_unet\")\nBEST_MODEL = os.path.join(MODEL_DIR, \"best_model.pth\")\ndef step4():\n   geoai.train_segmentation_model(\n       images_dir=f\"{TILES_DIR}/images\",\n       labels_dir=f\"{TILES_DIR}/labels\",\n       output_dir=MODEL_DIR,\n       architecture=CFG[\"architecture\"],\n       encoder_name=CFG[\"encoder\"],\n       encoder_weights=CFG[\"encoder_weights\"],\n       num_channels=CFG[\"num_channels\"],\n       num_classes=CFG[\"num_classes\"],\n       batch_size=CFG[\"batch_size\"],\n       num_epochs=CFG[\"num_epochs\"],\n       learning_rate=CFG[\"learning_rate\"],\n       val_split=CFG[\"val_split\"],\n       save_best_only=True,\n       early_stopping_patience=5,\n       verbose=True,\n   )\n   print(f\"\\n  best checkpoint: {BEST_MODEL}\")\n   print(f\"  size: {os.path.getsize(BEST_MODEL) / 1e6:.1f} MB\")\n   return BEST_MODEL\ntimed(step4, f\"STEP 4 — Training {CFG['architecture']}/{CFG['encoder']} \"\n             f\"for {CFG['num_epochs']} epochs\")\ndef step5():\n   hist_path = os.path.join(MODEL_DIR, \"training_history.pth\")\n   geoai.plot_performance_metrics(\n       history_path=hist_path,\n       figsize=(15, 5),\n       verbose=True,\n       save_path=os.path.join(WORK, \"training_curves.png\"),\n   )\n   h = torch.load(hist_path, weights_only=False)\n   best_ep = int(np.argmax(h[\"val_iou\"])) + 1\n   print(f\"\\n  best val IoU {max(h['val_iou']):.4f} at epoch {best_ep}\")\n   print(\"  Reading the curves: val loss rising while train loss falls => overfitting;\")\n   print(\"  both flat and high => underfitting (more epochs, bigger encoder, or more chips).\")\ntimed(step5, \"STEP 5 — Training diagnostics\")\n```\n\nWe train a U-Net semantic segmentation model with a ResNet-34 encoder using the prepared image and mask tiles. We configure the training process with validation splitting, early stopping, checkpoint saving, and performance monitoring. We then load the training history, plot the learning curves, and identify the epoch that produces the highest validation IoU.\n\n```\nPRED_MASK = os.path.join(WORK, \"test_prediction.tif\")\nPRED_PROB = os.path.join(WORK, \"test_probability.tif\")\ndef step6():\n   geoai.semantic_segmentation(\n       input_path=TEST_RASTER,\n       output_path=PRED_MASK,\n       model_path=BEST_MODEL,\n       architecture=CFG[\"architecture\"],\n       encoder_name=CFG[\"encoder\"],\n       num_channels=CFG[\"num_channels\"],\n       num_classes=CFG[\"num_classes\"],\n       window_size=CFG[\"window_size\"],\n       overlap=CFG[\"overlap\"],\n       batch_size=4,\n       probability_path=PRED_PROB,\n   )\n   geoai.print_raster_info(PRED_MASK, show_preview=False)\n   geoai.plot_prediction_comparison(\n       original_image=TEST_RASTER,\n       prediction_image=PRED_MASK,\n       titles=[\"NAIP test scene\", \"Predicted building mask\"],\n       figsize=(16, 8),\n       prediction_colormap=\"viridis\",\n       save_path=os.path.join(WORK, \"prediction_comparison.png\"),\n   )\n   with rasterio.open(PRED_MASK) as src:\n       m = src.read(1)\n       px = float(abs(src.transform.a) * abs(src.transform.e))\n   print(f\"  predicted building pixels: {int((m > 0).sum()):,} \"\n         f\"({100 * (m > 0).mean():.2f}% of scene, ~{(m > 0).sum() * px:,.0f} m2)\")\ntimed(step6, \"STEP 6 — Sliding-window inference on the test scene\")\nVEC_RAW = os.path.join(WORK, \"buildings_raw.geojson\")\nVEC_ORTHO = os.path.join(WORK, \"buildings_orthogonal.geojson\")\nVEC_FINAL = os.path.join(WORK, \"buildings_final.geojson\")\ndef step7():\n   grouped = geoai.region_groups(\n       PRED_MASK,\n       connectivity=2,\n       min_size=50,\n       out_image=os.path.join(WORK, \"test_prediction_cleaned.tif\"),\n   )\n   clean_mask = os.path.join(WORK, \"test_prediction_cleaned.tif\")\n   raw = geoai.raster_to_vector(\n       clean_mask,\n       output_path=VEC_RAW,\n       threshold=0,\n       min_area=15,\n       simplify_tolerance=0.5,\n   )\n   print(f\"  raw polygons        : {len(raw)}\")\n   ortho = geoai.orthogonalize(\n       input_path=clean_mask,\n       output_path=VEC_ORTHO,\n       epsilon=1.5,\n       min_area=15,\n   )\n   print(f\"  orthogonalized      : {len(ortho)}\")\n   final = geoai.regularization(ortho, angle_tolerance=12, simplify_tolerance=0.4)\n   final = geoai.add_geometric_properties(\n       final, properties=[\"area\", \"perimeter\", \"solidity\", \"elongation\", \"orientation\"]\n   )\n   final.to_file(VEC_FINAL, driver=\"GeoJSON\")\n   print(f\"  final footprints    : {len(final)}\")\n   print(final.head())\n   if \"area\" in final.columns:\n       print(\"\\n  footprint area stats (m2):\")\n       print(final[\"area\"].describe().round(1).to_string())\n   fig, axes = plt.subplots(1, 2, figsize=(16, 8))\n   with rasterio.open(TEST_RASTER) as src:\n       rgb = src.read([1, 2, 3]).transpose(1, 2, 0)\n       rgb = np.clip(rgb / np.percentile(rgb, 99), 0, 1)\n       ext = plotting_extent(src)\n   for ax, g, t in zip(axes, [raw, final], [\"Raw polygonization\", \"Orthogonalized + regularized\"]):\n       ax.imshow(rgb, extent=ext)\n       g.plot(ax=ax, facecolor=\"none\", edgecolor=\"red\", linewidth=1.1)\n       ax.set_title(t)\n       ax.set_axis_off()\n   plt.tight_layout()\n   plt.show()\n   try:\n       display(geoai.view_vector_interactive(VEC_FINAL, layer_name=\"Predicted buildings\"))\n   except Exception:\n       pass\n   return final\nFINAL_GDF = timed(step7, \"STEP 7 — Vectorizing and regularizing the predicted footprints\")\n```\n\nWe apply sliding-window inference to an unseen NAIP scene and generate both prediction and probability rasters. We remove small noisy regions, convert the predicted mask into vector polygons, and regularize the footprint geometries to produce cleaner building boundaries. We also calculate geometric properties and compare the raw polygonized results with the orthogonalized and regularized outputs.\n\n``` python\ndef step8():\n   gt_raster = os.path.join(WORK, \"train_gt_mask.tif\")\n   geoai.vector_to_raster(\n       vector_path=TRAIN_VECTOR,\n       output_path=gt_raster,\n       reference_raster=TRAIN_RASTER,\n       fill_value=0,\n       all_touched=True,\n       dtype=np.uint8,\n   )\n   train_pred = os.path.join(WORK, \"train_prediction.tif\")\n   geoai.semantic_segmentation(\n       input_path=TRAIN_RASTER,\n       output_path=train_pred,\n       model_path=BEST_MODEL,\n       architecture=CFG[\"architecture\"],\n       encoder_name=CFG[\"encoder\"],\n       num_channels=CFG[\"num_channels\"],\n       num_classes=CFG[\"num_classes\"],\n       window_size=CFG[\"window_size\"],\n       overlap=CFG[\"overlap\"],\n       quiet=True,\n   )\n   metrics = geoai.calc_segmentation_metrics(\n       ground_truth=gt_raster,\n       prediction=train_pred,\n       num_classes=2,\n       metrics=[\"iou\", \"f1\"],\n   )\n   print(\"\\n  --- pixel-wise metrics (class 0 = background, class 1 = building) ---\")\n   for k, v in metrics.items():\n       print(f\"  {k:<10}: {np.round(v, 4)}\")\n   print(\"\\n  Building-class IoU is the number that matters; background IoU is inflated\")\n   print(\"  by the huge negative class and always looks great.\")\n   geoai.plot_prediction_comparison(\n       original_image=TRAIN_RASTER,\n       prediction_image=train_pred,\n       ground_truth_image=gt_raster,\n       titles=[\"Imagery\", \"Prediction\", \"Ground truth\"],\n       figsize=(18, 6),\n       save_path=os.path.join(WORK, \"accuracy_comparison.png\"),\n   )\n   return metrics\nMETRICS = timed(step8, \"STEP 8 — Quantitative accuracy assessment\")\ndef step9():\n   if not CFG[\"run_zero_shot\"]:\n       print(\"  disabled in CFG\"); return\n   chip = os.path.join(WORK, \"test_chip.tif\")\n   with rasterio.open(TEST_RASTER) as src:\n       b = src.bounds\n       cx, cy = (b.left + b.right) / 2, (b.bottom + b.top) / 2\n       half = min((b.right - b.left), (b.top - b.bottom)) / 6\n       bbox = [cx - half, cy - half, cx + half, cy + half]\n   geoai.clip_raster_by_bbox(TEST_RASTER, chip, bbox=bbox, bbox_type=\"geo\")\n   print(f\"  clipped chip: {chip}\")\n   sam = geoai.GroundedSAM(\n       detector_id=\"IDEA-Research/grounding-dino-tiny\",\n       segmenter_id=\"facebook/sam-vit-base\",\n       tile_size=1024,\n       overlap=128,\n       threshold=0.3,\n   )\n   out_mask = os.path.join(WORK, \"zeroshot_mask.tif\")\n   gdf = sam.segment_image(\n       input_path=chip,\n       output_path=out_mask,\n       text_prompts=[\"building\", \"house\", \"rooftop\"],\n       polygon_refinement=True,\n       export_polygons=True,\n       min_polygon_area=30,\n       simplify_tolerance=1.5,\n   )\n   geoai.plot_prediction_comparison(\n       original_image=chip,\n       prediction_image=out_mask,\n       titles=[\"Chip\", \"Zero-shot: 'building / house / rooftop'\"],\n       figsize=(14, 7),\n       prediction_colormap=\"viridis\",\n   )\n   print(f\"  zero-shot objects found: {len(gdf) if gdf is not None else 0}\")\n   geoai.empty_cache()\ntimed(step9, \"STEP 9 — Zero-shot text-prompted segmentation (Grounding DINO + SAM)\")\n```\n\nWe evaluate the segmentation model by comparing its predictions with rasterized ground-truth building labels. We calculate pixel-level IoU and F1 metrics and visualize the imagery, predictions, and reference masks together. We then apply Grounding DINO and SAM to perform zero-shot building segmentation using text prompts without additional model training.\n\n``` python\ndef step10():\n   if not CFG[\"run_pretrained\"]:\n       print(\"  disabled in CFG\"); return\n   extractor = geoai.BuildingFootprintExtractor(model_path=\"building_footprints_usa.pth\")\n   gdf = extractor.process_raster(\n       TEST_RASTER,\n       output_path=os.path.join(WORK, \"buildings_maskrcnn.geojson\"),\n       batch_size=4,\n       confidence_threshold=0.5,\n       overlap=0.25,\n       mask_threshold=0.5,\n       min_object_area=100,\n       filter_edges=True,\n   )\n   if gdf is None or len(gdf) == 0:\n       print(\"  no instances returned\"); return\n   print(f\"  building instances: {len(gdf)}\")\n   reg = extractor.regularize_buildings(gdf, min_area=20, angle_threshold=15)\n   reg.to_file(os.path.join(WORK, \"buildings_maskrcnn_regularized.geojson\"), driver=\"GeoJSON\")\n   extractor.visualize_results(TEST_RASTER, gdf=reg, figsize=(12, 12))\n   if FINAL_GDF is not None:\n       print(f\"\\n  your U-Net      : {len(FINAL_GDF)} polygons\")\n       print(f\"  pretrained R-CNN: {len(reg)} polygons\")\n       print(\"  Different counts are expected: U-Net merges adjacent roofs, Mask R-CNN splits\")\n       print(\"  them into instances. Pick the paradigm that matches your downstream question.\")\n   geoai.empty_cache()\ntimed(step10, \"STEP 10 — Pretrained Mask R-CNN instance segmentation\")\ndef step11():\n   if not CFG[\"run_real_aoi\"]:\n       print(\"  disabled (set CFG['run_real_aoi'] = True to run; needs open internet)\")\n       return\n   bbox = (-83.9400, 35.9500, -83.9250, 35.9600)\n   items = geoai.pc_stac_search(\n       collection=\"naip\",\n       bbox=list(bbox),\n       time_range=\"2021-01-01/2023-12-31\",\n       max_items=3,\n   )\n   print(f\"  STAC items found: {len(items)}\")\n   aoi_dir = os.path.join(WORK, \"aoi\")\n   tif = geoai.download_naip(bbox=bbox, output_dir=aoi_dir, max_items=1, preview=False)\n   print(f\"  NAIP: {tif}\")\n   ovt = os.path.join(aoi_dir, \"overture_buildings.geojson\")\n   geoai.download_overture_buildings(bbox=bbox, output=ovt, overture_type=\"building\")\n   print(f\"  Overture buildings: {ovt}\")\n   print(geoai.extract_building_stats(ovt))\n   raster = tif[0] if isinstance(tif, (list, tuple)) else tif\n   geoai.export_geotiff_tiles(\n       in_raster=raster,\n       out_folder=os.path.join(aoi_dir, \"tiles\"),\n       in_class_data=ovt,\n       tile_size=512,\n       stride=256,\n   )\n   print(\"  AOI dataset ready — feed it to train_segmentation_model() exactly as in STEP 4.\")\ntimed(step11, \"STEP 11 — (optional) Real AOI: Planetary Computer NAIP + Overture Maps labels\")\ndef step12():\n   outputs = [f for f in sorted(os.listdir(WORK))\n              if f.endswith((\".tif\", \".geojson\", \".png\", \".pth\"))]\n   print(\"  artifacts produced:\")\n   for f in outputs:\n       print(f\"    {os.path.getsize(os.path.join(WORK, f)) / 1e6:8.2f} MB  {f}\")\n   zip_path = os.path.join(WORK, \"geoai_results.zip\")\n   subprocess.run(\n       [\"zip\", \"-qr\", zip_path, \".\", \"-i\", \"*.geojson\", \"*.png\", \"*.tif\", \"-x\", \"*tiles*\"],\n       cwd=WORK, check=False,\n   )\n   print(f\"\\n  bundle: {zip_path}\")\n   if IN_COLAB:\n       print(\"  Download it with:  from google.colab import files; \"\n             \"files.download('%s')\" % zip_path)\ntimed(step12, \"STEP 12 — Results summary\")\nbanner(\"DONE\")\nprint(\"\"\"\nWhere to go next\n----------------\n* Swap the head, keep the code: architecture=\"deeplabv3plus\", encoder_name=\"efficientnet-b3\"\n (or any timm encoder) in train_segmentation_model().\n* 4-band NAIP (RGB+NIR): num_channels=4 everywhere; the first conv is auto-adapted.\n* Multi-class land cover: geoai.train_segmentation_landcover() + geoai.export_landcover_tiles(),\n with DiceLoss / FocalLoss / TverskyLoss from geoai.landcover_train for class imbalance.\n* Instance segmentation you train yourself: geoai.train_MaskRCNN_model() then\n geoai.instance_segmentation(..., vectorize=True).\n* Object detection with georeferenced boxes: geoai.train.object_detection() /\n geoai.object_detection(text=\"cars\") for open-vocabulary Grounding DINO.\n* Foundation models: geoai.prithvi_inference (NASA/IBM Prithvi), geoai.universat_inference,\n geoai.DINOv3GeoProcessor for embeddings and similarity maps.\n* Change detection: geoai.change_detection (torchange backends).\n* Deploy: geoai.export_to_onnx() + geoai.onnx_semantic_segmentation(), or the QGIS plugin.\nDocs and notebooks: https://opengeoai.org  |  Book: https://book.opengeoai.org\n\"\"\")\n```\n\nWe use a pretrained Mask R-CNN model to extract individual building instances and compare them with the U-Net results. We optionally create a real-world dataset by downloading NAIP imagery from Microsoft Planetary Computer and matching building labels from Overture Maps. We finally collect the generated rasters, vectors, plots, and model outputs into a compressed results package for further analysis or download.\n\nIn conclusion, we completed an end-to-end geospatial deep learning pipeline that transforms raw aerial imagery into structured and analysis-ready building footprint data. We prepared training samples, trained and evaluated a semantic segmentation model, generated seamless predictions, and refined raster outputs into orthogonalized vector geometries with useful spatial attributes. We also examined alternative extraction approaches through zero-shot foundation models and pretrained instance segmentation, which helps us understand the trade-offs between custom training, prompt-based detection, and ready-to-use models. By packaging the generated masks, probability rasters, evaluation plots, trained weights, and GeoJSON outputs, we created a reusable foundation that we can adapt for land-cover mapping, infrastructure detection, change analysis, and large-scale GeoAI applications.\n\nCheck out the** Full Codes here. **Also, feel free to follow us on\n\n**and don’t forget to join our**[Twitter](https://x.com/intent/follow?screen_name=marktechpost)\n\n**and Subscribe to**\n\n[150k+ML SubReddit](https://www.reddit.com/r/machinelearningnews/)**. Wait! are you on telegram?**\n\n[our Newsletter](https://www.aidevsignals.com/)\n\n[now you can join us on telegram as well.](https://t.me/machinelearningresearchnews)Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? [Connect with us](https://forms.gle/wbash1wF6efRj8G58)\n\nSana Hassan, a consulting intern at Marktechpost and dual-degree student at IIT Madras, is passionate about applying technology and AI to address real-world challenges. With a keen interest in solving practical problems, he brings a fresh perspective to the intersection of AI and real-life solutions.", "url": "https://wpnews.pro/news/a-tutorial-on-geoai-designing-footprint-extraction-from-naip-imagery-using-u-net", "canonical_source": "https://www.marktechpost.com/2026/08/02/a-tutorial-on-geoai-designing-footprint-extraction-from-naip-imagery-using-u-net-grounding-dino-sam-and-mask-r-cnn/", "published_at": "2026-08-02 21:19:48+00:00", "updated_at": "2026-08-02 22:14:40.235140+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "computer-vision", "ai-tools"], "entities": ["GeoAI", "U-Net", "ResNet-34", "Grounding DINO", "SAM", "Mask R-CNN", "Microsoft Planetary Computer", "Overture Maps"], "alternates": {"html": "https://wpnews.pro/news/a-tutorial-on-geoai-designing-footprint-extraction-from-naip-imagery-using-u-net", "markdown": "https://wpnews.pro/news/a-tutorial-on-geoai-designing-footprint-extraction-from-naip-imagery-using-u-net.md", "text": "https://wpnews.pro/news/a-tutorial-on-geoai-designing-footprint-extraction-from-naip-imagery-using-u-net.txt", "jsonld": "https://wpnews.pro/news/a-tutorial-on-geoai-designing-footprint-extraction-from-naip-imagery-using-u-net.jsonld"}}