Field Polygon Generation with Machine Learning
Posted on: July 09, 2022The objective of this project is to generate polygons representing farm shapes based on the GPS data from harvesters or planters working on them.
While GPS data provides a series of points that the machine passed through, there is no programmatic way to determine the correct shapes of the farms, as they are very irregular and there can be data losses. Therefore, a Machine Learning model was trained with the FastAI library to determine the shape of the farm based on these points and return it as a polygon.
The first step is to generate a series of images with GPS points inside them, based on farms whose shape is already known. The format that FastAI accepts for segmentation problems like this is: a PNG image from which the prediction will be made, and a binary mask (also in PNG) that indicates which points belong to the farm and which do not.
A segmentation model is trained which returns a probability matrix of whether a point belongs to the farm based on an image with the points.
Knowing the coordinates of the corners of the images generated for the prediction, the obtained matrix can be converted back into a polygon, discarding points with a low probability of belonging to the farm. For this, the Imantics library is also used, which has some utilities for this conversion.
Finally, we obtain a result as a shapely polygon. In the previous image we have:
- On the left: LineString of the vehicle’s route
- In the center: Individual points of the LineString (this is used as input for the model)
- On the right: Resulting polygon obtained by the model.
An unexpected utility is that the model generalizes in such a way that even in farms where there is little data, a polygon is obtained that fits sufficiently well to the correct shape.