← All blogs

Computer vision

Pothole detection with YOLOv12, SAM and Depth Anything V2

In a research experiment, we trained a YOLOv12 model to find potholes, then tried to answer the question a road crew would ask next: how big is it? Detection went well. Size and depth came with error bars of ±35% and ±50%, because the photos had no camera metadata and we had to assume how they were taken.

Rubix Labs5 min read
Pipeline from our pothole experiment: YOLOv12s detection with test AP50 0.832 and validation mAP50 0.8759, SAM vit_b masks prompted by each box with mean score 0.9305, Depth Anything V2 Small relative depth at plus or minus 50%, and a road-plane projection at plus or minus 35%. The same 452 detections rated HIGH severity 11 times from boxes and 3 times from masks. None of 121 images had EXIF data.
From our research experiment on 149 held-out test images. With no camera metadata, every size and depth figure rests on an assumed camera height and angle; these are estimates for ranking, not measurements.

Training the detector

We trained YOLOv12s, with 9,096,851 parameters, from its standard small configuration for 50 epochs at 640 pixels and batch 8. The labelled set had 1,482 images and 5,014 pothole boxes: 1,037 images for training, 296 for validation and 149 for testing, with 144 images containing no pothole at all. Training took 0.185 hours, about 11 minutes, on one RTX 5090.

A separate validation run at confidence 0.25 and IoU 0.45 gave precision 0.8528, recall 0.8035, mAP50 0.8759 and mAP50-95 0.5553. On the 149 held-out test images the detector never saw in training, AP50 was 0.832 and AP50-95 was 0.514. Ultralytics reported 0.8 ms and 1.8 ms of model inference per image in its two validation runs, plus a little pre- and post-processing. Those are batched GPU validation timings, not what a laptop would see.

A box overstates how bad it is

Our first severity score mixed box area with how low the pothole sat in the frame: 60% normalised area and 40% vertical position, with cut-offs at 0.20 and 0.40. On the test images it rated 452 detections as 255 LOW, 186 MEDIUM and 11 HIGH.

A rectangle around an irregular hole includes plenty of road. So we prompted Segment Anything, using the vit_b checkpoint, with each detection box and measured the mask instead. Across the 452 masks the mean SAM score was 0.9305, with a minimum of 0.8214, and on average 98.70% of each mask sat inside its box. Using mask area and rotated-rectangle dimensions, severity became 371 LOW, 78 MEDIUM and 3 HIGH: the same detections, with a very different repair list.

Neither version is a road-engineering scale. Both are triage heuristics until someone checks them against field measurements.

Metres need a camera you don't have

To turn a mask into metres, we projected it onto a flat road plane through a pinhole camera model. That needs the camera's height, tilt and field of view. None of the 121 test images with detections had EXIF data, so we assumed a small drone camera: 83° horizontal field of view, 24 mm equivalent focal length, 3.0 m altitude and a 75° downward tilt. We put ±35% on every size estimate because of that assumption.

Depth came from Depth Anything V2 Small, which estimates relative depth. We mapped its contrast to centimetres with a heuristic scale and carried ±50%. Mean estimated depth came out around 1.89 cm, with a maximum around 10.78 cm. That's useful for ranking which potholes look deeper and nowhere near good enough for a repair specification.

The projection also shows you when the assumption breaks. Mean calibrated length was 0.759 m and width 0.368 m, with a median area of 0.0748 m². Six detections were flagged as inconsistent with the assumed camera, including one 'pothole' of 20.5433 m². That's most likely a close-up or low-angle photo meeting a 3-metre altitude assumption, and the flag caught it.

Metres need a camera you don't have
StageModelWhat it gave usLimit
DetectionYOLOv12sTest AP50 0.832Boxes include road around the hole
ShapeSAM vit_b with box promptsMean mask score 0.9305Masks can extend past the box; none leaked more than 25% here
DepthDepth Anything V2 SmallRelative depth mapHeuristic centimetre scale, ±50%
SizePinhole road-plane projectionMedian area 0.0748 m²Assumed camera, ±35%

Small and distant potholes

Perspective photos shrink distant potholes to a few pixels. We added an optional mode that runs the detector at 960 pixels with confidence 0.28 instead of 640 and 0.40, adds overlapping tiles and merges the candidates with non-maximum suppression before masking. It's slower and adds low-confidence candidates. We haven't measured its recall gain on a labelled set yet, so treat it as a switch to evaluate rather than a known improvement.

Two dull bugs that stopped the run

The labelled folder contained 2,976 hidden macOS '._' sidecar files. They aren't images or labels, but the dataset loader tried to read them and failed. Deleting them fixed loading. If your data has passed through a Mac and a zip file, look for these first.

The second was a version pin. In the YOLOv12 package we used, validation called numpy.trapz, which newer NumPy 2.4 builds don't have. We pinned NumPy 1.26.4 and an OpenCV build compatible with it, and validation ran again.

Licences, and the next step

Check the licences before this becomes a commercial service. The YOLOv12 repository we trained with is AGPL-3.0, and SAM is Apache 2.0. Depth Anything V2 Small is Apache-2.0, while its Base, Large and Giant models are CC-BY-NC-4.0, so swapping in a bigger depth model for accuracy changes what you're allowed to do with the result.

The next step is ground truth: potholes with tape-measured size and depth, photographed at a known altitude and angle. Rubix can help plan that capture and the evaluation around it. Our pricing page lists detection and measurement with existing vision models, including a review step for uncertain results, under computer vision solutions.