Daily Tech Briefing
AI 科技速览

每天 5 分钟内学习 AI。获取最新的人工智能新闻,理解其重要性,并学习如何将其应用于您的工作。

AI 快讯
MarkTechPost · 2026/8/2 21:19:48

A Tutorial on GeoAI: Designing Footprint Extraction from NAIP Imagery Using U-Net, Grounding DINO, SAM, and Mask R-CNN

AI 中文解读
这是一篇非常实用的GeoAI教程,核心亮点在于手把手教你把多种顶尖AI模型组合起来,从高空航拍图中自动“圈出”每一栋建筑物,堪称给AI装上“天眼”。普通人可以这样理解:过去要靠人工在卫星照片上一点点描出房屋轮廓,现在只要训练好AI,它就能自己认房、勾边,甚至把歪歪扭扭的线条修正成规整的图形,效率提升几个量级。教程也不是纸上谈兵,它带着读者从下载真实影像数据开始,一步步训练U-Net模型,同时对比Grounding DINO、SAM、Mask R-CNN等不同方法的识别
In this tutorial, we design a complete 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. Copy CodeCopiedUse a different Browserimport os import subprocess import sys import time import warnings warnings.filterwarnings("ignore") IN_COLAB = "google.colab" in sys.modules def pip_install(packages, quiet=True): """Install packages with pip from inside the notebook process.""" cmd = [sys.executable, "-m", "pip", "install", "--upgrade"] if quiet: cmd.append("-q") subprocess.run(cmd + list(packages), check=False) try: import geoai except ImportError: print(">>> Installing geoai-py and friends (takes ~2-4 minutes on Colab)...") pip_install( [ "geoai-py", "segmentation-models-pytorch", "buildingregulariser", ] ) try: import geoai except Exception as e: raise SystemExit( f"Import failed after install ({e}).\n" "=> Runtime > Restart session, then re-run this cell. " "The install is cached, so it will be fast the second time." ) import geopandas as gpd import matplotlib.pyplot as plt import numpy as np import rasterio import torch from rasterio.plot import plotting_extent from IPython.display import display print(f"geoai : {geoai.__version__}") print(f"torch : {torch.__version__}") print(f"CUDA available: {torch.cuda.is_available()}") if torch.cuda.is_available(): print(f"GPU : {torch.cuda.get_device_name(0)}") else: print("!! No GPU detected. Training will still run but be much slower.") print(" Colab: Runtime > Change runtime type > Hardware accelerator > T4 GPU") DEVICE = geoai.get_device() print(f"geoai device : {DEVICE}") CFG = { "tile_size": 512, "stride": 256, "buffer_radius": 0, "architecture": "unet", "encoder": "resnet34", "encoder_weights": "imagenet", "num_channels": 3, "num_classes": 2, "batch_size": 8, "num_epochs": 12, "learning_rate": 1e-3, "val_split": 0.2, "window_size": 512, "overlap": 256, "run_zero_shot": True, "run_pretrained": True, "run_real_aoi": False, } WORK = "/content/geoai_tutorial" if IN_COLAB else os.path.abspath("geoai_tutorial") os.makedirs(WORK, exist_ok=True) os.chdir(WORK) print(f"working dir : {WORK}") def banner(text): print("\n" + "=" * 92 + f"\n {text}\n" + "=" * 92) def timed(fn, label): """Run fn(), report wall time, never let one step kill the notebook.""" banner(label) t0 = time.time() try: out = fn() print(f"\n[OK] {label} — {time.time() - t0:.1f}s") return out except Exception as exc: import traceback print(f"\n[SKIPPED] {label}\n{type(exc).__name__}: {exc}") traceback.print_exc(limit=3) return None HF = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main" train_raster_url = f"{HF}/naip_rgb_train.tif" train_vector_url = f"{HF}/naip_train_buildings.geojson" test_raster_url = f"{HF}/naip_test.tif" def step1(): train_raster = geoai.download_file(train_raster_url) train_vector = geoai.download_file(train_vector_url) test_raster = geoai.download_file(test_rast
分享
阅读原文