Tale of our approach to a real-world problem- Farm Patch Alignment System.

Sanskar Jaiswal
Data Kisaan
Published in
5 min readFeb 26, 2021

One cannot harness the power of data without an innovative robust algorithm. As a Data Science Intern in Carnot Technologies, I was expected to develop an automated and precise farm patch cover alignment pipeline. It was my first exposure to real-life data, and indeed real-world problems are quite daunting. But my mentor Yash supported me all throughout from gradually getting familiar with “Geographic Information System” packages and utilities to creating our own patch alignment algorithm. I got stuck at a lot of places but found answers to all the problems along the way.

The geo-spatial coordinates of the tractor’s location from IoT sensors installed on them were the only raw data we had. The GPS coordinate data has too much noise due to which directly using them to generate patches results in visually unpleasant irregular output. And our task was to come up with accurate results using the raw geospatial data. Mapping the latitude-longitude coordinates to image pixel values was another hurdle. But some research and reading a few articles helped.

The first primary task was to do semantic segmentation of the patch points resulting in a binary mask. We designed a U-net-based fully convolutional Deep learning(DL) model for the task. But the satellite images we generated for training had quite varied texture, color, shape, and size. It is common for farms of the Indian Subcontinent to be this diverse. But somehow, we came up with a solution where the threshold of segmentation by our DL model was varied to generalize the results for each plot. The challenges and the solution with our DL model are further explained by my co-intern in this article.

Time to Innovate

This was just the start. Next, we came up with a really innovative idea, where we considered a donut-shaped buffer containing the patch boundary generated from the raw data, and we tried to sample possible candidate patches that were more aligned (i.e. visually appealing) with the real patch. And finally, we thought we’d select the best out of those sampled patches.

The first attempt towards the approach was to sample black pixels along the edges of the Deep Learning output and form polygons out of it and check their relative fitness with the real patch. But soon we realized that the computation complexity to go over a hell lot of permutations would be extreme. And the fact that our model was meant to efficiently generate results in real-time could not be out focused.

(To the left) is the raw satellite image of the farm area, a human can easily figure out the patch boundaries. But the farms being of different colours shape and texture, training a deep learning model was a great challenge. (To the right ) is the Deep learning mask output. The patch surfaces are smooth and hence this segmentation was not enough.

The Breakthrough

Now, we were back to the same stage where we started, but this time we came up with a better approach; at least for the time being, we shifted to detect the real patch’s optimum corner candidates, which lied inside the buffer. We developed a corner detection algorithm and implemented it on the Deep learning’s output and we got a few hundred points for each corner of the patch. Considering in general a patch has four corners, the combination of corners was huge and it required about a “Trillion” iterations to get the corners for the best possible result. Although this new approach was efficient with respect to the previous. But, it was still computationally expensive. Now, looking for a better solution, we just wondered if we can use the “Genetic Algorithm” to make selections. Genetic Algorithm is a “natural evolution” inspired optimization technique, where we considered a random collection (Population) of all the possible candidates of corners for each corner of a particular farm patch and did random mutations and crossovers of coordinate values of the candidate polygon generation for multiple iterations, which is how evolution happens over multiple generations for a species. The mere effort of experimenting with this idea actually proved to be ground-breaking.

The required number of iterations was brought down from trillions to a few thousand. We used the “Intersection over Union” metric to select the best 20 candidates which were passed to the next generation. But the metric was not so efficient due to noise in data. At this moment, we realized that the immediate gradient of colors on either side of the edges could be a discriminative factor and let us align the patch more accurately. Hence we changed our fitness function and also devised a Protrusion Detection and Slant Edge Correction Algorithm. Thus, a new hybrid pipeline was created.

The real patch shape is too irregular and it is surrounded by lots of bushes, still, our model outputs a much aligned and proper patch.

Final Blackbox Algorithm

But our task was still not over, we had three outputs in hand i.e. from our Deep Learning model, Genetic algorithm approach, and the Hybrid pipeline, and each one of them was better in their own way. We finally created our final Blackbox which outputs the best result for a patch considering various conditions such as Range of the Area of all outputs, number of corners of patches, etc.

The gradual need for an increase in the accuracy and our perfectly aligned output is perfectly summarised by the above pictures.

Results and Conclusion

Finally, our hard work paid off and the results were way beyond my imagination. We manually tagged around 200 patches to be confident enough about the model. Out of the 200, for 198 patches the results proved to enhance user experience.

Optimization is at the heart of the creation of a robust and generalized algorithm. We need ways to carve our path out of the challenges efficiently with minimal resources and simultaneously produce the best results. This project certainly brought about a lot of difference in the way I used to approach problems.

References and Further Reading:-

[1] Genetic Algorithm Implementation using Python

[2] U-Net: Convolutional Networks for Biomedical Image Segmentation

Enjoyed this article? Then be on the lookout for another two weeks later. Till then, for any data-related discussions, feel free to drop us a line at datalabs@carnot.co.in. And don’t forget to follow Data Kisaan on Medium.

--

--

Sanskar Jaiswal
Data Kisaan

Undergraduate @ Indian Institute of Technology Bombay