Blog

1 juillet 2018 · TensorFlow · Raspberry Pi

Speeders come out when the street is empty

A home-made speed camera on a Berlin street logged more than 150,000 motor vehicles in spring 2018. Few broke the 50 km/h limit, 0.6%, but the rate tripled at dawn and more than doubled in the quietest hours.

Article en anglais.

At 6h on a Berlin street, 1.3% of motor vehicles were driving faster than 50 km/h. Three hours later, in the morning rush, the share was 0.4%. Speeding here is rare, but it is not random: it happens when the road is empty enough to allow it.

The figures come from a Raspberry Pi and a webcam looking down on the street, which recorded a speed and a photograph for every moving object between 5 April and 27 May 2018. After removing duplicate files, that is 212,490 readings on 46 days, almost all of them between 6h and 20h. A neural network trained on hand-labelled photographs sorted the readings into bikes and everything else: 151,744 motor-vehicle readings (cars, but also buses, vans and motorbikes) and 60,735 bikes.

Figure 1

The camera measures every object that crosses the frame and keeps a photograph of it

One frame from the speed camera, with the estimated speed printed at the bottom · April 2018

View from above of a street lined with parked cars; a yellow city bus and a cyclist cross the detection rectangle, with the caption SPEED 27.4 kph
The red rectangle is the detection zone · Photo and analysis: Timeit data team

Most traffic is slow; a small minority breaks the limit

The typical motor vehicle passed the camera at 24 km/h (median), the typical bike at 18 km/h. Only 927 of the 151,543 motor-vehicle readings taken between 6h and 20h were above 50 km/h, Germany's default urban limit: 0.61%. That average hides a clear daily pattern.

The rate is highest in the first hour of recording, from 6h to 7h, and falls to its lowest at 9h, after the morning peak. It rises again around midday, to 0.85% between 12h and 13h, and settles near the average for the afternoon and evening rush.

The quieter the hour, the higher the share of speeders

Time of day is a proxy for something simpler: how much traffic there is. Counting the motor vehicles recorded in each complete clock hour and grouping the hours by that count shows a steady gradient. In hours with fewer than 200 vehicles, 0.97% of drivers exceeded 50 km/h. In hours with 500 or more, 0.43% did, less than half the rate.

The week tells the same story. Sunday, the quietest day, with an average of 226 motor vehicles per complete hour against 377 on weekdays, had a speeding rate of 1.02%, against 0.56% from Monday to Friday. Saturday sat in between, at 0.65%.

Other explanations fare worse. Across the 29 days with at least twelve hours of recording, the daily speeding rate shows no relationship with the mean temperature measured at the Berlin-Tegel weather station (correlation coefficient 0.10), and only a weak negative one with the number of bikes on the street (-0.37). Rain made no visible difference either: in the 49 recorded hours with precipitation at the Berlin-Tempelhof station, 0.55% of drivers exceeded 50 km/h, against 0.62% in dry hours.

Not one street's quirk: the whole city speeds up at dawn

Berlin's traffic detectors, which count vehicles and measure their speed on the main roads, show the same daily rhythm. Across 264 detector sites away from the motorways, over the same seven weeks, the average speed was highest at 6h, at 46.3 km/h, and lowest at 8h, at 42.1 km/h, the morning peak. It dipped again in the afternoon rush and recovered in the evening. On the camera's street, the 6h hour was 10% faster than the street's daily average; across the detectors, 6% faster. Over the 14 hours from 6h to 19h, the two hourly profiles move together, with a correlation of 0.65.

That supports the simple explanation: when the roads empty, everyone drives faster, and on a street where most traffic moves at about 24 km/h, a faster flow pushes more drivers over 50. It does not prove it. The two sources measure different roads, and an hourly average says nothing about any individual driver.

How the camera and the classifier were built

The speed measurement uses the open-source speed-camera project, an OpenCV script that tracks moving objects across the frame and converts their displacement into a speed after a one-off calibration. Each reading comes with a photograph, stored in the cloud.

To tell bikes from cars, about 19,000 photographs were labelled by hand in roughly 15 hours, with a small web tool built for the purpose, the Mechanical French, using ten categories (car, bike, bus, taxi, pedestrian, delivery van, truck, motorbike, ambulance, undefined). The categories were very unbalanced, so the model was trained as a binary classifier, bike or not bike. It is a small convolutional network built from scratch, three convolution and pooling layers followed by a dense layer, without transfer learning. It trained in about two hours on a low-end graphics card and reached 97% accuracy on the validation set.

About the data

What was measured: one reading per object detected by the camera, with a timestamp, an estimated speed and a direction of travel. The classifier label "car" covers every motor vehicle. Readings were de-duplicated on the image file name, and the analysis keeps the hours from 6h to 20h, when the camera ran.

Caveats. Speeds are estimates from a single consumer webcam and depend on the calibration; individual readings, including the fastest ones, should not be taken at face value, and the 50 km/h threshold is used as a marker, not as proof of an offence. The camera may record a vehicle more than once, so readings are not a traffic count. Recording was interrupted on several days, by a faulty USB cable and later by the Raspberry Pi being unplugged. Figure 3 uses only complete clock hours, with readings in the first and last five minutes and in at least 50 distinct minutes of the hour. A classifier with 97% accuracy still mislabels some readings: 89 "bikes" were clocked above 50 km/h.

Open data. Daily weather: Deutscher Wetterdienst, station Berlin-Tegel, as used in the original analysis. Hourly precipitation: DWD Climate Data Center, station Berlin-Tempelhof (00433), timestamps converted from UTC to local time. Traffic detectors: Digitale Plattform Stadtverkehr Berlin / Verkehrsdetektion Berlin, hourly values per measuring cross-section for April and May 2018 (data licence Germany, attribution, version 2.0); sites on motorways (roads named A…) were excluded using the detector master list, and speeds are averaged weighted by vehicle count. The detector sites are mostly on main roads, not on the camera’s street, so Figure 4 compares the shape of the daily profiles, not their level. Code and data: github.com/clementlefevre/Fast_and_Curious. Tools: Raspberry Pi, OpenCV, Keras and TensorFlow, R; figures recomputed with DuckDB.