Skip to content

About

Weak labels from NVDB geometry on Statens vegvesen's road photos, a multi-label CNN, and a map of where photos and register disagree.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Guardrail inspector

Is the national road register right about guardrails? This project combines Norway's open road data with deep learning to check. NVDB (Nasjonal vegdatabank) records where guardrails stand and their inspection status. Statens vegvesen photographs most national and county roads every year. The pipeline joins the two, trains a model on the register's own geometry as weak supervision, and maps the stretches where photos and register disagree.

Driving along the E6 near Trondheim: the model's guard-rail probability for each side next to the road register

A stretch of the E6 the model never trained on. For every photo it gives the probability of a guard rail on each side; the shaded band is what the road register says.

weak labels on real road photos Random photos from Trondheim with labels generated automatically from NVDB geometry (L/R = guardrail left/right, eL/eR = guardrail end ahead, -1 = ambiguous, ignored in training). Photos: Statens vegvesen, NLOD.

Norsk: Verktøyet sammenstiller rekkverk i NVDB med Statens vegvesens vegbilder. En modell trenes på svake etiketter fra NVDB-geometrien, og strekninger der bildene og NVDB er uenige (rekkverk som mangler i registeret, eller som er registrert men ikke synlig) markeres i et kart.

How it works

flowchart LR
    A[NVDB API<br/>rekkverk 5, ender 14,<br/>tilstand 947 / 284] --> C[weak labels per photo<br/>camera-frame geometry]
    B[Vegbilder WFS<br/>position, heading, URL] --> C
    C --> D[spatial split<br/>1 km cells]
    D --> E[CNN multi-label, EfficientNet-B3<br/>masked BCE, flip = swap L/R]
    E --> F[predictions along each drive]
    F --> G[deviation stretches<br/>model ≠ NVDB]
    G --> H[GeoJSON + TypeScript map viewer]
Loading
  1. Data. nvdb.py pages through NVDB API Les v4 (guardrails, end terminals, inspection results). vegbilder.py queries the Vegbilder WFS in tiles: one forward-looking photo every ~20 m, with position and heading. Both use EPSG:25833.
  2. Weak labels (labels.py). Each guardrail polyline is densified to 1 m points and transformed into every camera's frame (forward / left from the heading). A guardrail counts as visible on the left when ≥ 5 m of it lies 4-25 m ahead and left of the vehicle. Borderline cases get label −1 and are masked out of the loss. Inspection records (Tiltaksbehov = needs action) near the visible guardrail, at most three years old, give a noisier fifth label.
  3. Training (train.py). A timm backbone with five sigmoid outputs and masked, class-weighted BCE. A horizontal flip mirrors the scene, so the augmentation also swaps the left/right labels. Train/val/test are split by 1 km grid cell, so neighbouring photos of the same guardrail never leak across splits.
  4. Deviations (deviations.py). Photos are ordered by road metre within each drive. Three or more consecutive photos where the model and NVDB disagree become a stretch: unregistered (seen, not in NVDB) or not seen (in NVDB, not in the photos).
  5. Viewer (viewer/). TypeScript + MapLibre on Kartverket's topographic map: NVDB guardrails, inspection flags, photo positions coloured by the model, and deviation stretches with example photos.

Results

Trondheim (kommune 5001), 2023-2024 photos, weak labels from NVDB, test split = held-out 1 km cells:

Model AP left AP right AP end left AP end right mAP
ConvNeXt-T (ImageNet-22k) 0.970 0.922 0.420 0.490 0.701
ConvNeXt-T (DINOv3) 0.973 0.932 0.453 0.587 0.736
EfficientNet-B3, deployed 0.980 0.939 0.567 0.518 0.751
ResNet-50 0.969 0.916 0.468 0.549 0.725

Every backbone finds the guardrails themselves (AP 0.92-0.98); the end terminals are where they differ (0.42-0.59), small objects that appear in few photos. EfficientNet-B3 had the best validation mAP (0.712) and was picked for the predictions and the deviation map before the test split was scored; it is also the best on test. The ConvNeXt-T with DINOv3 weights beats the same network with ImageNet weights by 0.035 mAP, most of it on the end terminals.

The two ConvNeXt-T rows share the architecture, input size and schedule; the pretraining differs. The default uses supervised ImageNet-22k weights. The DINOv3 variant is distilled from Meta's self-supervised DINOv3 ViT-7B, trained on 1.7 billion web images (LVD-1689M). Its dense features are reported to transfer well to new domains, and road photos from a vehicle camera are far from ImageNet. The comparison measures whether that helps with weak labels. DINOv3 weights come under Meta's DINOv3 licence, not Apache 2.0.

The self-supervised DINOv3 backbone is fine-tuned gently: it trains at 1/20 of the classifier's learning rate (optim.backbone_lr_mult=0.05, 1.5e-5), chosen with a short learning-rate sweep.

The labels themselves come from the register, so a high AP means the model agrees with NVDB. The interesting part is the residual: the deviation map lists where they disagree, for a human to check.

Quickstart

pip install -e ".[train]"
gi-build --bbox 262000 7028000 276000 7042000 --years 2024 --out data/trondheim --max-images 3000 --download
gi-train --config configs/convnext_tiny.yaml --set data.root=data/trondheim \
    --set model.backbone=efficientnet_b3.ra2_in1k --set name=effnet_b3_guardrails
gi-predict --checkpoint runs/effnet_b3_guardrails/best.pt --dataset data/trondheim --split all
gi-deviations --predictions runs/effnet_b3_guardrails/predictions_all.parquet --out deviations.geojson
gi-export-viewer --dataset data/trondheim --predictions runs/effnet_b3_guardrails/predictions_all.parquet \
    --deviations deviations.geojson --out viewer/public/data
cd viewer && npm ci && npm run dev       # http://localhost:5173

Training on a GPU cluster (Slurm)

The dataset build needs internet access, so it runs on a login node. Training and inference run as jobs:

bash scripts/setup_cluster.sh && bash scripts/download_models.sh
bash scripts/build_dataset.sh                      # Trondheim, ~30k photos
python3 slurm/generate.py train --submit
python3 slurm/generate.py backbones --submit       # array: ConvNeXt-T DINOv3, EfficientNet-B3, ResNet-50
python3 slurm/generate.py evaluate --submit        # test-split AP of all four
python3 slurm/generate.py predict --submit         # with the best model on validation
python3 slurm/generate.py deviations --submit

The pixel-level stage (train-yolo-seg) trains YOLO26-seg, the newest Ultralytics segmentation model, on masks corrected in CVAT, for measuring guardrail extent and damage inside the photo. It runs with the NMS-free head (nms=False); Ultralytics 8.4 otherwise validates the auxiliary one-to-many head with NMS.

Project layout

src/guardrail_inspector/
  nvdb.py           NVDB API Les v4 client (pagination, caching, flattening to GeoDataFrames)
  vegbilder.py      Vegbilder WFS client and image downloader
  labels.py         camera-frame visibility -> weak labels; NVDB inspection records -> needs-action label
  build.py          area -> GeoParquet layers, sampled photos, spatial split, labels.csv
  data.py, train.py masked multi-label training with left/right-aware augmentation
  predict.py        per-photo probabilities + AP per label
  deviations.py     runs of disagreement along each drive -> GeoJSON
  export_viewer.py  GeoJSON layers + thumbnails for the viewer
viewer/             TypeScript + MapLibre GL + Vite
tests/              geometry of the weak labels, API parsing on recorded responses, deviations, training smoke test

Data and licences

NVDB and Vegbilder are published by Statens vegvesen under the Norwegian Licence for Open Government Data (NLOD 2.0). The base map is © Kartverket (CC BY 4.0). Vegbilder are anonymised (faces and number plates) by Statens vegvesen. The repository contains no photos except the small sample above. gi-build downloads them on demand.

References

  • Z. Liu et al., A ConvNet for the 2020s (ConvNeXt), CVPR 2022.
  • O. Siméoni et al., DINOv3, arXiv:2508.10104, 2025.

About

Weak labels from NVDB geometry on Statens vegvesen's road photos, a multi-label CNN, and a map of where photos and register disagree.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages