Skip to content

Leverage machine learning to aid in the tagging of drivable ways (i.e. roads) in OpenStreetMap.

License

Notifications You must be signed in to change notification settings

jdalrym2/road_surface_classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenStreetMap Road Surface Classifier

OSM Logo OSM Logo

This project leverages machine learning (ML) to tag "drivable ways" (roads) in OpenStreetMap with > 95% accuracy. The main focus at the moment is automating tagging of the road surface type (paved vs. unpaved; but skill is shown for asphalt, concrete, gravel, etc.), with other helpful tags such as number of lanes to be added in the future.

⚠️ Much of this code is under active development. Breaking changes are to be expected.

Table of Contents

Why Should I Care...

... About OpenStreetMap?

Most geospatial data, like that provided in Google Maps, are locked behind licensing and paywalls. Maps should not be proprietary. OpenStreetMap aims to change this, by providing open geospatial data for everyone. See more here.

... About this Project?

Road surface type is critical for routing applications to generate useful routes. For example, nominal driving speeds are much slower on unpaved roads vs. paved roads. For bicycles, unpaved routes may need to be avoided completely. In any case, lacking knowledge of road surface type can lead any OSM-based routing application to choose suboptimal routes if the assumed default surface values are incorrect. Widespread labeling of road surface types can increase overall confidence in OSM-based routers as a viable routing solution for cars and bicycles alike.

Integration with the OSM Community

I foresee the following possible integrations with the OpenStreetMap community:

  • Provide a dataset that can augment OSM routing solutions, such as Project OSRM, Valhalla, and cycle.travel.
  • Integrate the above dataset into editors such as JOSM or Rapid. I'm prototyping a plugin for JOSM at the moment.

Python Environment

I recommend pip-tools to manage the environment for this project. The gist for to set up a Python environment for this repo would be:

$ cd /.../road_surface_classifier          # cd into project directory
$ python3 -m venv ./venv                   # create Python virtual env
$ . venv/bin/activate                      # activate env
(venv) $ python3 -m pip install pip-tools  # install pip-tools
(venv) $ pip-sync                          # automatically installs dependencies!

Training Dataset

The dataset used in this project was prepared by the process outlined in project notebooks. It is the aggregation of OpenStreetMap data w/ National Agriculture Imagery Program (NAIP) imagery, which is public domain. I additionally have a routine that generates pseudo-truth segmentation masks which the model learns to predict.

Currently the dataset has been automatically generated, but in some cases has issues related to the visibility of the roads due to vegetation growth (though the model is trained to predict this). Also of note is that there is no guarantee the labels set in OSM are correct, so we must trust that the vast majority of them are correct. A big source of confusion, for example, is asphalt vs. concrete. It would not surprise me if there are many mislabeled examples of these within OSM.

❗ NAIP imagery is limited to the United States. While there are other public domain imagery sources that can be used, none have global coverage.

NAIP Imagery Example

Examples of NAIP imagery over roads. These are Web Mercator tiles at zoom level 16 (~2.3 meters per pixel). However, the model is trained on raw NAIP data which includes NIR and is 1 meter per pixel. (source: USGS National Agriculture Imagery Program)

To support the MaskCNN architecture (see below), binary masks were also generated in order to tell the model "where to look":

NAIP Imagery + Masks Example

Examples of NAIP imagery over roads with OSM labels (paved vs. unpaved) and generated binary masks from OSM data. (source: USGS National Agriculture Imagery Program [imagery]; OpenStreetMap [labels])

Model Architecture

I'm currently using a MaskCNN model largely based on Liu et al.: Masked convolutional neural network for supervised learning problems.

  • Instead of multiplication, I concatenate the predicted mask into the classifier backbone.
  • I'm using a Resnet-18 backbone for both the encoder, decoder, and classifier.
  • By using such a small encoder, this can inference on a CPU!

MCNN Figure

Quick diagram of the MaskCNN architecture used here. The NAIP imagery gets combined with a mask created from OSM vector data, which in-turn is used to generate the segmentation mask. The image and segmentation mask are then fed into the classifier model.

The benefit of this model over a plain Resnet is the ability to tell the model what the mask should look like. This tells the classifier "where to look" (i.e. I care about this road in the image, not that one).

The trick is to not force the appearance of this mask too much, because then (1) the model stops looking outside the mask after the concatenation step and (2) the model will care about the mask more than the classification result!

Model Training

Training is currently done w/ PyTorch Lightning, see train.py.

❗ I don't recommend training this model without a dedicated compute GPU configured with CUDA. I know some use Google Colab, but I'm unfamiliar.

Training Results

To read the confusion matrix, for each box, read "when the true label is X, then __% of the time the models predicts Y".

Paved vs. Unpaved

Confusion matrix for paved vs. unpaved model

Not bad! The model gets each category right over 95% of the time.

Multiclass

Confusion matrix for full multiclass model

Given the imagery resolution, often obscuration of vegetation, and often incorrect truth labels this is impressive. The model clearly shows skill in predicting a wider range of classes than just paved vs. unpaved.

Credits

MaskCNN Paper

Liu, L. Y. F., Liu, Y., & Zhu, H. (2020). Masked convolutional neural network for supervised learning problems. Stat, 9(1), e290.

License

MIT © 2024 Jonathan Dalrymple

About

Leverage machine learning to aid in the tagging of drivable ways (i.e. roads) in OpenStreetMap.

Resources

License

Stars

Watchers

Forks

Packages

No packages published