Improving the Rwandan crop data
16 July 2026In my previous post I wrote a classifier for identifying three different crops (beans, maize, and potatoes) from photos taken of Rwandan farm plots. The data was pretty imbalanced, and the classifier was fairly poor. In this post I address that, in two ways.
First, I now use only a subset of the bean and maize photos. I take 1.4x the number of potato images, and then weight my loss function by those proportions. This yields an improvement, but recall for potatoes is still around 30%, i.e. no better than a random guess.
I then started asking myself what kind of images the model was categorising correctly, or incorrectly. Looking at some examples, the problem is clear: many of the photo tiles do not contain crops at all.1

Fortunately, filtering for the presence of plants is easy, because they are green! My filter computes the average RGB values for each tile and rejects if green is not the dominant colour. This requires only two matrix multiplications per tile, and the improvement is immediate.

There are still some patches of sky passing the green filter, and I remove these by filtering by brightness – my heuristic is that the tile is too bright if the average sum of the RGB values across the tile is greater than 500. At the same time I filter dark images with a lower bound of 100. I then adjust all remaining tiles to a fixed brightness of 300, because the model was otherwise learning to classify by brightness.

All this massively improves the performance of the classifier. The final thing I want to do is test the trained classifier on full images again, rather than on 240x240px tiles. That’s for next time!
-
Showing here only the tiles classified as maize. All images copyright (CC-BY-4.0) Benson Kipkemboi Kenduiywo, Anastasia Wahome, Stephen Sande Ngondi, Joseph Chemutt, Marie Ange Tesire, Samuel Ishimwe, Yves Hategekimana, Lilian Ndungu, Golo Rademacher, Aniruddha Ghosh. ↩