Teaching a Neural Network to See Roads
By: Laura Lewis
Tags: Neural Networks, London, Data Science, Image Recognition, Machine Learning

The problem

Each year about 1.25 million people worldwide die in road traffic accidents, and an additional 20–50 million are injured or disabled. If the locations of traffic accidents could be predicted, this could have a huge beneficial impact in potentially helping to reduce the number of accidents each year. For example, routing software could avoid the most dangerous areas — particularly in the context of the coming advent of driverless cars. It could also be useful in an insurance context, in order to predict risk, as well as for governments and local road authorities looking to create more efficient systems of road maintenance and improvements.

The solution

With this in mind, I recently finished a project with Sabatino Chen to try and tackle this problem, using various forms of deep learning to predict where traffic accidents are likely to occur. We were particularly interested in answering this question:

Does using satellite imagery improve the ability of a model to predict traffic accidents?

We built three types of model in total to predict aspects of traffic accidents:

Using structured data on traffic accidents, population density and traffic to try and predict the severity of an accident Using satellite imagery to try and predict whether an area was ‘safe’ (no traffic accidents) or ‘dangerous’ (traffic accidents) A fancy mixed-data model that combines the outputs of a multi-layer perceptron trained on structured data and a convolutional neural network trained on satellite imagery into a final neural network layer head

This article is about model 2, and how we built a convolutional neural network (CNN) to predict how dangerous a given area is in terms of traffic accidents (but fear not, the fancy model 3 will be the subject of a future blog post — it’s pretty bad-ass).

The data

We chose London as our testing ground — partly because the UK Office of National Statistics has some very comprehensive high-quality data on traffic accidents, population and traffic; partly because London is a big built-up city with a mix of city centre areas, suburbs and major and minor roads, which provides a good variety of images for training; and partly because I live here and have a vested interest in not being hit by a car.

The full code for this project can be found in my GitHub repo. Data sources include the UK Department for Transport’s (DfT) Road Safety Data, the DfT’s Road Traffic Counts (yes, we really do employ people to stand at street corners and count cars), and data from the UK’s 2011 Census, as well as satellite images courtesy of the Google Maps Static API.

The method

The area we chose was a square I drew around the outside of the M25, which is the big motorway (highway, for my American audience) that circles London, in order to include a wide range of road types:

In order to get a set of ‘dangerous’ and ‘safe’ areas which do not overlap, a grid system was created and used by splitting London into squares of 0.0005 latitude x 0.0005 longitude. This resulted in grid squares (technically rectangles) of 56m high (latitude) and 35m wide (longitude), similar to the 30m x 30m commonly used as suitable size for traffic accident analysis.

The image below shows this grid square system superimposed over a map of traffic accident locations in central London, to give a sense of scale (the accident locations trace the road system fairly effectively):

Bonus points if you can spot the Strand and the Thames

Once we had a list of the total set of grid squares, we used the accident dataset to figure out which squares had had or had not had traffic accidents in the last five years. These became our ‘dangerous’ and ‘safe’ classes. We then used the Google Maps Static API to download images for each square in a random sample of 5,000 ‘dangerous’ areas and 5,000 ‘safe’ areas.

The images below show the first five images downloaded from the random sample of each class. They show that dangerous areas include roads in suburban areas, larger roads and junctions (e.g. roundabouts, which are very common in the UK), but that not all images are necessarily only of roads — for example, the fourth image also contains a green area alongside the road where the accident/s occurred.

Safe areas include green areas with no roads (unsurprisingly), but also contain suburban areas with roads which have similarities with those where accidents did occur. These images will likely be more difficult for the CNN to classify, but are also important for it to learn from, as they will mean that the CNN is not just learning the differences between roads and fields but is also learning the differences between different types of road.

The model

We tried three iterations of CNNs to try and produce the most accurate model. The first version we tried was a fairly straightforward CNN model architecture using Keras, with three pairs of Conv2D and MaxPooling2D layers and one dense layer before the final sigmoid activated layer. It did pretty well, with test accuracy (average F1 score) of 72% and no over-fitting.

Here’s the code for our baseline model:

For the second iteration of our model, we built on top of the the VGG19 pre-trained model with ImageNet weights, and extracted features by running our images through it first before training a new classifier on top of the outputs. We reached a test accuracy of 74%, but with notable over-fitting (i.e. the training set achieved much higher accuracy).

For our final iteration we used L1 regularization to try and combat the over-fitting. To try and improve accuracy we increase the image input size, and added an extra dense layer to the classifier head just for good measure.

The results

The final iteration was our best model, achieving 77% accuracy and minimal over-fitting. The code for building the model is a bit convoluted (no pun intended), but it’s available in my GitHub repo in notebook 6. Here are the results:

Classification reports (top is the training set, bottom is the test set) and confusion matrix for the final model

The main thing I would like to improve upon is to increase the recall and reduce the proportion of false positives — predicting 1 = safe when the area is actually 0 = danger. In this context, these types of errors can be seen as more costly compared to a model predicting dangerous areas when they are actually safe.

The future

To try and improve the accuracy of the model and remove overfitting entirely, some of the following could be tried in further model iterations:

Download more images for use in training

Use a different pre-trained model, e.g. ResNet50, which has been used in other CNNs for satellite imagery (e.g. here and here)

Freeze specific layers of the pre-trained model and fine-tune other layers

Change the architecture of the densely connected classifier on top of the pre-trained model (e.g. adding more layers or nodes)

Nevertheless, being able to correctly predict 77% of the time whether or not an area is likely to have a traffic accident from a satellite image alone is still pretty impressive.